There are no reviews yet. Be the first to send feedback to the community and the maintainers!
Repository Details
Hello JavaScript code newbie! In this repository I'm proposing you a series of coding challenges that will help you practice the basic language constructs and algorithms.
JavaScript Coding Challenges
01. Creates a function that takes two numbers as arguments and return their sum.
functionaddition(a,b){//Write Your solution Here};console.log(addition(10,20));// 30console.log(addition(30,20));// 50console.log(addition(10,90));// 100
05. Write functions to calculate the bitwise AND, bitwise OR and bitwise XOR of two numbers.
functionbitwiseAND(n1,n2){//Write Your solution Here};functionbitwiseOR(n1,n2){//Write Your solution Here};functionbitwiseXOR(n1,n2){//Write Your solution Here};console.log(bitwiseAND(10,20));// 0console.log(bitwiseOR(10,20));// 30console.log(bitwiseXOR(10,20));// 30
18. Your function will be passed two functions, f and g, that don't take any parameters. Your function has to call them, and return a string which indicates which function returned the larger number.
If f returns the larger number, return the string f.
If g returns the larger number, return the string g.
If the functions return the same number, return the string neither.
functionwhichIsLarger(f,g){//Write Your solution Here};console.log(whichIsLarger(()=>25,()=>15));// fconsole.log(whichIsLarger(()=>25,()=>25));// neitherconsole.log(whichIsLarger(()=>25,()=>50));// g
19. Christmas Eve is almost upon us, so naturally we need to prepare some milk and cookies for Santa! Create a function that accepts a Date object and returns true if it's Christmas Eve (December 24th) and false otherwise. Keep in mind JavaScript's Date month is 0 based, meaning December is the 11th month while January is 0.
functiontimeForMilkAndCookies(date){//Write Your solution Here};console.log(timeForMilkAndCookies(newDate(3000,11,24)));//trueconsole.log(timeForMilkAndCookies(newDate(2013,0,23)));//falseconsole.log(timeForMilkAndCookies(newDate(3000,11,24)));//true
20. function that takes a two-digit number and determines if it's the largest of two possible digit swaps.
functionlargestSwap(num){//Write Your solution Here};console.log(largestSwap(14));//falseconsole.log(largestSwap(53));//trueconsole.log(largestSwap(-27));//false
21. function that takes two strings as arguments and returns the number of times the first string (the single character) is found in the second string.
functioncharCount(myChar,str){//Write Your solution Here};console.log(charCount("a","largest"));//1console.log(charCount("c","Chamber of secrets"));// 2console.log(charCount("b","big fat bubble"));//4
22. function that takes two parameters and repeats the string n number of times.
functionrepetition(txt,n){//Write Your solution Here};console.log(repetition('zim',5));//zimzimzimzimzimconsole.log(repetition('zoy',2));//zoyzoyconsole.log(repetition('akib',7));//akibakibakibakibakibakibakib
24. Write a function that take a string and write a regular expression inner function that returns the value that matches every red flag and blue flag in this string.
functionmatchFlag(str){//Write Your solution Here};console.log(matchFlag("yellow flag red flag blue flag green flag"));//[ 'red flag', 'blue flag' ]console.log(matchFlag("yellow flag green flag orange flag white flag"));//nullconsole.log(matchFlag("yellow flag blue flag green flag"));//[ 'blue flag' ]
27. Create a function that takes a string and returns a string in which each character is repeated once.
functiondoubleChar(str){//Write Your solution Here};console.log(doubleChar('jahidul'));//jjaahhiidduullconsole.log(doubleChar('islam'));//iissllaammconsole.log(doubleChar('zim'));//zziimm
28. Write a function that takes a positive integer and return its factorial.
functionfactorial(num){//Write Your solution Here};console.log(factorial(5));//120console.log(factorial(10));//3628800console.log(factorial(8));//40320
31. Create a function that takes a string and returns the number (count) of vowels contained within it.
functioncountVowels(str){//Write Your solution Here};console.log(countVowels('Jahidul Islam zim'));// 6console.log(countVowels('returns the number of vowels'));// 8console.log(countVowels('JavaScript Coding Challenges'));// 8
32. Create a function that takes two vectors as arrays and checks if the two vectors are orthogonal or not. The return value is boolean. Two vectors a and b are orthogonal if their dot product is equal to zero.
functionisOrthogonal(arr1,arr2){//Write Your solution Here};console.log(isOrthogonal([1,-2,4],[2,5,2]));//trueconsole.log(isOrthogonal([1,-2,5],[2,5,2]));//falseconsole.log(isOrthogonal([1,2,4],[-2,5,-2]));//true
33. Given an object of how many more pages each ink color can print, output the maximum number of pages the printer can print before any of the colors run out.
34. Create a function that takes a string and returns a new string with all vowels removed.
functionremoveVowels(str){//Write Your solution Here};console.log(removeVowels('Jahidul Islam Zim'));//Jhdl slm Zmconsole.log(removeVowels('a new string with all vowels'));// nw strng wth ll vwlsconsole.log(removeVowels('Create a function'));//Crt fnctn
36. Given an array of scrabble tiles, create a function that outputs the maximum possible score a player can achieve by summing up the total number of points for all the tiles in their hand. Each hand contains 7 scrabble tiles.
37. Assume a program only reads .js or .jsx files. Write a function that accepts a file path and returns true if it can read the file and false if it can't.
functionisJS(path){//Write Your solution Here};console.log(isJS('file.jsx'));//true console.log(isJS('file.jsg'));//falseconsole.log(isJS('file.js'));//true
38. A farmer is asking you to tell him how many legs can be counted among all his animals. The farmer breeds three species:
chickens = 2 legs
cows = 4 legs
goats = 4 legs
The farmer has counted his animals and he gives you a subtotal for each species. You have to implement a function that returns the total number of legs of all the animals.
functionanimals(chickens,cows,goats){//Write Your solution Here};console.log(animals(2,3,5))// 36console.log(animals(1,2,3))// 22console.log(animals(5,2,8))// 50
41.Create a function that takes two strings as arguments and return either true or false depending on whether the total number of characters in the first string is equal to the total number of characters in the second string.
functioncomp(str1,str2){//Write Your solution Here};console.log(comp("AB","CD"));//trueconsole.log(comp("ABC","DE"));//falseconsole.log(comp("WE","RT"));// true
42.A vehicle needs 10 times the amount of fuel than the distance it travels. However, it must always carry a minimum of 100 fuel before setting off. Create a function which calculates the amount of fuel it needs, given the distance.
functioncalculateFuel(n){//Write Your solution Here};console.log(calculateFuel(15));//150 console.log(calculateFuel(23.5));//235console.log(calculateFuel(3));//100
44.Create a function that returns true if an integer is evenly divisible by 5, and false otherwise.
functiondivisibleByFive(n){//Write Your solution Here};console.log(divisibleByFive(5));//trueconsole.log(divisibleByFive(-55));//falseconsole.log(divisibleByFive(37));//true
45. Create a function that takes in an array of numbers and returns the sum of its cubes.
functionsumOfCubes(nums){//Write Your solution Here};console.log(sumOfCubes([1,2,3,4,5]));//255console.log(sumOfCubes([5,2,7,4,0]));//540console.log(sumOfCubes([1,6,3,9,5]));//1098
46.A group of friends have decided to start a secret society. The name will be the first letter of each of their names, sorted in alphabetical order. Create a function that takes in an array of names and returns the name of the secret society.
functionsocietyName(friends){//Write Your solution Here};console.log(societyName(['zim','zoy','shithil','akib']));//zzsaconsole.log(societyName(['Rakib','Taskin','shomrat','Prionty']));//RTsPconsole.log(societyName(['Ratul','Rakib','Ritu','Taj']));//RRRT
47. Create two functions: isPrefix(word, prefix-) and isSuffix(word, -suffix).
isPrefix should return true if it begins with the prefix argument.
isSuffix should return true if it ends with the suffix argument.
Otherwise return false.
functionisPrefix(word,prefix){//Write Your solution Here};functionisSuffix(word,suffix){//Write Your solution Here};console.log(isPrefix("automation","auto-"));//trueconsole.log(isPrefix("retrospect","sub-"));//falseconsole.log(isSuffix("arachnophobia","-phobia"));//trueconsole.log(isSuffix("vocation","-logy"));//false
49. Create a function that takes an array of 10 numbers (between 0 and 9) and returns a string of those numbers formatted as a phone number (e.g. (555) 555-5555).
functionformatPhoneNumber(numbers){//Write Your solution Here};console.log(formatPhoneNumber([1,2,3,4,5,6,7,8,9,0]));//(123) 456-7890console.log(formatPhoneNumber([1,2,0,4,5,3,8,1,9,0]));//(120) 453-8190console.log(formatPhoneNumber([1,7,9,4,2,6,8,8,5,0]));//(179) 426-8850
50. Write a regular expression that matches only an even number. Numbers will be presented as strings.
functionmatchEven(str){//Write Your solution Here};console.log(matchEven("3458"));//8console.log(matchEven("3517"));//Undefinedconsole.log(matchEven("4902"));//2
51. Create a function that returns the index of the first vowel in a string.
functionfirstVowel(str){//Write Your solution Here};console.log(firstVowel("zimislam"));//1console.log(firstVowel("akib"));//0console.log(firstVowel("shomrat"));//2
54. Given a higher bound num, implement a function that returns an array with the sequence of numbers, after that every multiple of 4 has been amplified by 10.
55. Given an array of 10 numbers, return the maximum possible total made by summing just 5 of the 10 numbers.
functionmaxTotal(nums){//Write Your solution Here};console.log(maxTotal([1,1,0,1,3,10,10,10,10,1]));//43console.log(maxTotal([0,0,0,0,10,0,3,0,100]));// 113console.log(maxTotal([1,2,3,2,5,6,9,8,9,10]));//42
56. Write a regular expression that matches a string if and only if it is a valid zip code.
Must only contain numbers (no non-digits allowed).
Must not contain any spaces.
Must not be greater than 5 digits in length.
functionisValidZip(zip){//Write Your solution Here};console.log(isValidZip("393939"));//falseconsole.log(isValidZip("59001"));//trueconsole.log(isValidZip("853a7"));//false
57. Create a function that takes a number as an argument and returns the highest digit in that number.
functionhighestDigit(number){//Write Your solution Here};console.log(highestDigit(3456));//6console.log(highestDigit(21098));//9console.log(highestDigit(56123));//6
58. Create a function that takes a number as an argument and returns the highest digit in that number.
functionhighestDigit(number){//Write Your solution Here};console.log(highestDigit(3456));//6console.log(highestDigit(21098));//9console.log(highestDigit(56123));//6
59. Given an array of scrabble tiles, create a function that outputs the maximum possible score a player can achieve by summing up the total number of points for all the tiles in their hand. Each hand contains 7 scrabble tiles.
60.Create a function that takes an array as an argument and returns true or false depending on whether the average of all elements in the array is a whole number or not.
constisAvgWhole=(arr)=>{//Write Your solution Here};console.log(isAvgWhole([1,3]));// trueconsole.log(isAvgWhole([1,2,3,4]));// falseconsole.log(isAvgWhole([1,5,6]));// trueconsole.log(isAvgWhole([1,1,1]));// trueconsole.log(isAvgWhole([9,2,2,5]));// false