{"id":18928698,"url":"https://github.com/hamidhosen42/javascript-problem-solving","last_synced_at":"2026-05-03T09:36:13.757Z","repository":{"id":150277119,"uuid":"466471170","full_name":"hamidhosen42/javaScript-problem-solving","owner":"hamidhosen42","description":"JavaScript, often abbreviated JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. Over 97% of websites use JavaScript on the client side for web page behavior, often incorporating third-party libraries.","archived":false,"fork":false,"pushed_at":"2022-03-05T14:08:46.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-31T19:17:02.530Z","etag":null,"topics":["algorithms","api","javascript","json","problemsolving"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hamidhosen42.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-05T14:08:25.000Z","updated_at":"2022-03-14T13:30:26.000Z","dependencies_parsed_at":"2023-06-28T15:45:17.082Z","dependency_job_id":null,"html_url":"https://github.com/hamidhosen42/javaScript-problem-solving","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamidhosen42%2FjavaScript-problem-solving","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamidhosen42%2FjavaScript-problem-solving/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamidhosen42%2FjavaScript-problem-solving/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamidhosen42%2FjavaScript-problem-solving/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hamidhosen42","download_url":"https://codeload.github.com/hamidhosen42/javaScript-problem-solving/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239923824,"owners_count":19719204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","api","javascript","json","problemsolving"],"created_at":"2024-11-08T11:27:14.411Z","updated_at":"2026-03-15T22:30:18.375Z","avatar_url":"https://github.com/hamidhosen42.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaScript Problem Solving\n\n1. Print in Console numbers from 1 to 10\n2. Print in Console the odd numbers less than 100\n3. Print in Console the multiplication table with 7\n4. Calculate the sum of numbers from 1 to 10\n5. Calculate 10!\n6. Calculate the sum of odd numbers greater than 10 and less than 30\n7. Calculate the sum of numbers in an array of numbers\n8. Calculate the average of the numbers in an array of numbers\n9. Find the maximum number in an array of numbers\n10. Create a function that receives an array of numbers and returns an array containing only the positive numbers\n11. Print in Console all the multiplication tables with numbers from 1 to 10\n12. Create a function that will convert from Celsius to Fahrenheit\n13. Create a function that will convert from Fahrenheit to Celsius\n14. Print in Console the first 10 Fibonacci numbers without recursion\n15. Create a function that will find the nth Fibonacci number using recursion\n16. Check Leap Year Using if...else?\n17. Create a function that accepts an array and returns the last item in the array.\n18. Calculate the sum of digits of a positive integer number\n19. Print in Console the first 100 prime numbers\n20. Check Odd or Even Number with Arguments Objects\n21. Create a function that will return in an array the first \"nPrimes\" prime numbers greater than a particular number \"startAt\"\n22. Rotate an array to the left 1 position\n23. Reverse an array with createed function, don`t Change orginal array #24: Reverse an array with JavaScript Builtin Method\n24. Reverse a string with JavaScript Builtin Method\n25. Reverse a string with createed function, don`t Change orginal string\n26. Create a function that takes an array and returns the types of values (data types) in a new array.\n27. Create a function that will return in an array. becarefull function parameter and array length is same in count.\n28. Create a function that takes the age in years and returns the age in days.\n29. Create a function that takes voltage and current and returns the calculated power.\n30. Given two numbers, return true if the sum of both numbers is less than 50. Otherwise return false.\n31. Write a function that takes minutes and converts it to seconds.\n32. Write a function that converts hours into seconds.\n33. Create a function that takes an array containing only numbers and return the first element.\n34. Create a function that finds the maximum range of a triangle's third edge, where the side lengths are all integers.\n35. Write a function that takes the base and height of a triangle and return its area.\n36. Create a function that takes a number as an argument, increments the number by +1 and returns the result.\n37. Create a function that takes a base number and an exponent number and returns the calculation.\n38. Create a function that takes two numbers as arguments and return their sum.\n39. Create a function that will merge two arrays and return the result as a new array\n40. Create a function that will receive two arrays of numbers as arguments and return an array composed of all the numbers that are either in the first array or second array but not in both\n\n**#1: Print in Console from 1 to 10 numbers?**\n\n```\n\nfor (let i = 1; i \u003c= 10; i++) {\n  console.log(i);\n}\n\n```\n\n**#2: Print in Console the odd numbers less than 100?**\n\n```\n\nfor (let i = 1; i \u003c= 100; i += 2) {\n  console.log(i);\n}\n\n```\n\n**#3: Print in Console the multiplication table with 7?**\n\n```\n\nfor (let i = 1; i \u003c= 10; i++) {\n  console.log(`7 x ${i} = ${i * 7}`);\n}\n\n```\n\n**#4: Calculate the sum of numbers from 1 to 10?**\n\n```\n\nlet sum = 0;\nfor (let i = 1; i \u003c= 10; i++) {\n  sum += i;\n}\nconsole.log(sum);\n\n```\n\n**#5: Calculate 10!?**\n\n```\n\nlet fabCalculate = 1;\nfor (let i = 1; i \u003c= 10; i++) {\n  fabCalculate *= i;\n}\nconsole.log(fabCalculate);\n\n```\n\n**#6: Calculate the sum of odd numbers greater than 10 and less than 30?**\n\n```\n\nlet sumOdd = 0;\nfor (let i = 10; i \u003c= 30; i += 2) {\n  sumOdd += i;\n}\nconsole.log(sumOdd);\n\n```\n\n**#7: Calculate the sum of numbers in an array of numbers?**\n\n```\n\nlet arr = [50, 67, 20, 84, 91, 40, 69];\nlet arrTotal = 0;\nfor (let i = 0; i \u003c arr.length; i++) {\n  arrTotal += arr[i];\n}\nconsole.log(arrTotal);\n\n```\n\n**#8: Calculate the average of the numbers in an array of numbers?**\n\n```\n\nconst arrAverage = (arr) =\u003e {\n  let arrTotal = 0;\n  for (let i = 0; i \u003c arr.length; i++) {\n    arrTotal += arr[i];\n  }\n  return arrTotal / arr.length;\n};\nconsole.log(arrAverage(arr));\n\n```\n\n**#9: Find the maximum number in an array of numbers?**\n\n```\n\nconst findMaxNumber = (arr) =\u003e Math.max(...arr);\n\nconsole.log(findMaxNumber(arr));\n\n```\n\n**#10: Create a function that receives an array of numbers and returns an array containing only the positive numbers?**\n\n```\n\nconst getPositiveNumber = (arr) =\u003e {\n  const newArr = [];\n  for (let i = 0; i \u003c arr.length; i++) {\n    if (arr[i] % 2 == 0) {\n      newArr.push(arr[i]);\n    }\n  }\n  return newArr;\n};\nconsole.log(getPositiveNumber(arr));\n\n```\n\n**#11: Print in Console all the multiplication tables with numbers from 1 to 10?**\n\n```\n\nconst printMultiplicationTable = (n) =\u003e {\n  for (let i = 1; i \u003c= n; i++) {\n    for (let j = 1; j \u003c= 10; j++) {\n      console.log(`${i} x ${j} = ${i * j}`);\n    }\n  }\n};\nprintMultiplicationTable(10);\n\n```\n\n**#12: Create a function that will convert from Celsius to Fahrenheit?**\n\n```\n\nconst celsiustoFahrenheit = (n) =\u003e n * 1.8 + 32;\nconsole.log(celsiustoFahrenheit(50));\n\n```\n\n**#13: Create a function that will convert from Fahrenheit to Celsius?**\n\n```\n\nconst fahrenheittoCelsius = (n) =\u003e ((n - 32) * 5) / 9;\nconsole.log(fahrenheittoCelsius(50));\n\n```\n\n**#14: Create a function that will find the nth Fibonacci number using recursion?**\n\n```\n\nfunction findFibonacci(n) {\n  if (n == 0) return 0;\n\n  if (n == 1) return 1;\n\n  return findFibonacci(n - 1) + findFibonacci(n - 2);\n}\nconsole.log(findFibonacci(20));\n\n```\n\n**#15: Create a function that will return a Boolean specifying if a number is prime?**\n\n```\n\nfunction isPrime(num) {\n  for (var i = 2; i \u003c num; i++)\n    if (num % i === 0) {\n      return num \u003c 1;\n    }\n  return num \u003e 1;\n}\nconsole.log(isPrime(6));\n\n```\n\n**#16: Check Leap Year Using if...else?**\n\n```\n\nfunction checkLeapYear(year) {\n  if ((year % 4 == 0 \u0026\u0026 year % 100 != 0) || year % 400 == 0) {\n    return year \u003e 1;\n  } else {\n    return year \u003c 1;\n  }\n}\nconsole.log(checkLeapYear(2025));\n\n```\n\n**#17: Create a function that accepts an array and returns the last item in the array?**\n\n```\n\nconst arr = [50, 90, 80, 66, 85];\nconst returnLastItem = (arr) =\u003e arr[arr.length - 1];\nconsole.log(returnLastItem(arr));\n\n```\n\n**#18: Calculate the sum of digits of a positive integer number?**\n\n```\n\nconst sumOfDigits = (n) =\u003e {\n  const newArr = Array.from(String(n), Number);\n  let sumOfArr = 0;\n  for (let i = 0; i \u003c newArr.length; i++) {\n    sumOfArr += newArr[i];\n  }\n  return sumOfArr;\n};\nconsole.log(sumOfDigits(45465));\n\n```\n\n**#19: Print in Console the first 50 prime numbers**\n\n```\n\ngetPrime(50);\nfunction getPrime(nPrime) {\n  let prime = 1;\n  for (let i = 2; prime \u003c= nPrime; i++) {\n    if (isPrime(i)) {\n      console.log(prime, \" \", i);\n      prime++;\n    }\n  }\n}\n\nfunction isPrime(num) {\n  for (var i = 2; i \u003c num; i++)\n    if (num % i === 0) {\n      return num \u003c 1;\n    }\n  return num \u003e 1;\n}\n\n```\n\n**#20: Check Odd or Even Number with Arguments Objects**\n\n```\n\nfunction checkOddOrEven() {\n  for (let i = 0; i \u003c arguments.length; i++) {\n    arguments[i] % 2 == 0\n      ? console.log(arguments[i] + \" is Even Number\")\n      : console.log(arguments[i] + \" is Odd Number\");\n  }\n}\ncheckOddOrEven(11, 10, 20);\n\n```\n\n**#21: Create a function that will return in an array the first \"nPrimes\" prime numbers greater than a particular number \"startAt**\n\n```\n\nconsole.log(getFirstNprimeNumber(5, 500));\nfunction getFirstNprimeNumber(nPrimes, startAt) {\n  const arr = [];\n  for (let i = startAt; arr.length \u003c nPrimes; i++) {\n    if (isPrime(i)) {\n      arr.push(i);\n    }\n  }\n  return arr;\n}\nfunction isPrime(num) {\n  for (var i = 2; i \u003c num; i++)\n    if (num % i === 0) {\n      return num \u003c 1;\n    }\n  return num \u003e 1;\n}\n\n```\n\n**#22: Rotate an array to the left 1 position**\n\n```\n\nconst arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];\n\nrotateLeft(arr);\nfunction rotateLeft(arr) {\n  const arrFirstElement = arr.shift();\n  arr.push(arrFirstElement);\n}\nconsole.log(arr);\n\n```\n\n**#23: Reverse an array with createed function, don`t Change orginal array**\n\n```\n\nconst arr = [1, 2, 3];\n\nconst newArr = reverseArr(arr);\nconsole.log(newArr);\n\nfunction reverseArr(arr) {\nconst newArr = [];\nfor (let i = arr.length - 1; i \u003e= 0; i--) {\nnewArr.push(arr[i]);\n}\nreturn newArr;\n}\n\n\n```\n\n**#24: Reverse an array with JavaScript Builtin Method**\n\n```\n\nconst arr = [1, 2, 3];\narr.reverse();\nconsole.log(arr);\n\n```\n\n**#25: Reverse a string with createed function, don`t Change orginal string**\n\n```\n\nconst str = \"Md Nazmul Islam\";\n\nconst newStr = reverseString(str);\nconsole.log(newStr);\n\nfunction reverseString(str) {\n  let newStr = \"\";\n  for (let i = str.length - 1; i \u003e= 0; i--) {\n    newStr += str[i];\n  }\n  return newStr;\n}\n\n```\n\n**#26: Reverse a string with JavaScript Builtin Method**\n\n```\n\nconst str = \"Md Nazmul islam\";\nconst newStr = str.split(\"\").reverse().join(\"\");\nconsole.log(newStr);\n\n```\n\n**#27: Create a function that takes an array and returns the types of values (data types) in a new array.**\n\n```\n\nconst arrayValuesTypes = (arr) =\u003e {\n  const newArr = [];\n  for (let i = 0; i \u003c arr.length; i++) {\n    newArr.push(typeof arr[i]);\n  }\n  return newArr;\n};\nconsole.log(arrayValuesTypes([1, 2, \"Nazmul\", [], true]));\n\n```\n\n**Or ShortCut**\n\n```\n\nconst arrayValuesTypes = (arr) =\u003e arr.map((x) =\u003e typeof x);\nconsole.log(arrayValuesTypes([1, 2, \"Nazmul\", [], true]));\n\n```\n\n**#28: Create a function that will return in an array. becarefull function parameter and array length is same in count.**\n\n```\n\nfunction getArray(number) {\n  var newArray = [];\n  for (var i = 1; i \u003c= number; i++) {\n    newArray.push(i);\n  }\n  return newArray;\n}\nconsole.log(getArray(5));\n\n```\n\n**Or ShortCut**\n\n```\n\nconst getArray = (n) =\u003e Array(...Array(n)).map((v, i) =\u003e i + 1);\nconsole.log(getArray(5));\n\n```\n\n**#29: Create a function that takes the age in years and returns the age in days.**\n\n```\n\nconst calcAge = (age) =\u003e (age \u003c 0 || typeof age != \"number\" ? null : age * 365);\nconsole.log(calcAge(5));\n\n```\n\n**#30: Create a function that takes voltage and current and returns the calculated power.**\n\n```\n\nconst circuitPower = (voltage, current) =\u003e voltage * current;\nconsole.log(circuitPower(115, 5));\n\n```\n\n**#31: Given two numbers, return true if the sum of both numbers is less than 50. Otherwise return false.**\n\n```\n\nfunction lessThan50(a, b) {\n  if (a + b \u003c 50) {\n    return true;\n  } else {\n    return false;\n  }\n}\nconsole.log(lessThan50(40, 30));\n\n```\n\n**Or ShortCut**\n\n```\n\nconst lessThan50 = (a, b) =\u003e a + b \u003c 50;\nconsole.log(lessThan50(30.15));\n\n```\n\n**#32: Write a function that takes minutes and converts it to seconds.**\n\n```\n\nconst minuteToSecond = (minutes) =\u003e minutes * 60;\nconsole.log(minuteToSecond(2));\n\n```\n\n**#33: Write a function that converts hours into seconds.**\n\n```\n\nconst hoursToSeconds = (hours) =\u003e hours * 60 * 60;\nconsole.log(hoursToSeconds(2));\n\n```\n\n**#34: Create a function that takes an array containing only numbers and return the first element.**\n\n```\n\nconst getFirstValueOfArray = (arr) =\u003e arr[0];\n\n```\n\n**#35: Create a function that finds the maximum range of a triangle's third edge, where the side lengths are all integers.**\n\n```\n\nconst nextEdge = (side1, side2) =\u003e side1 + side2 - 1;\n\n```\n\n**#36: Write a function that takes the base and height of a triangle and return its area.**\n\n```\n\nconst triangleArea = (base, height) =\u003e (base * height) / 2;\n\n```\n\n**#37: Create a function that takes a number as an argument, increments the number by +1 and returns the result.**\n\n```\n\nconst incrementsNumber = (n) =\u003e ++n;\n\n```\n\n**#38: Create a function that takes a base number and an exponent number and returns the calculation.**\n\n```\n\nconst calculateExponent = (num, exp) =\u003e Math.pow(num, exp);\n\n```\n\n**#39: Create a function that takes two numbers as arguments and return their sum.**\n\n```\n\nfunction addition(a, b) {\n  if (typeof a !== \"number\" || typeof b !== \"number\") {\n    return \"Sorry you didn't pass two numbers.\";\n  }\n  return a + b;\n}\n\n```\n\n**#40: Create a function that will merge two arrays and return the result as a new array**\n\n```\n\nconst mergeArrays = (arr1, arr2) =\u003e {\n  return [...arr1, ...arr2];\n};\nconsole.log(mergeArrays([5, 3, 6], [8, 7]));\n\n```\n\n**// Or**\n\n```\n\nfunction mergeArrays(arr1, arr2) {\n  var arr = [];\n\n  for (let element of arr1) {\n    arr.push(element);\n  }\n\n  for (let element of arr2) {\n    arr.push(element);\n  }\n\n  return arr;\n}\nconsole.log(mergeArrays([5, 3, 6], [8, 7]));\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamidhosen42%2Fjavascript-problem-solving","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhamidhosen42%2Fjavascript-problem-solving","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamidhosen42%2Fjavascript-problem-solving/lists"}