Skip to content

Instantly share code, notes, and snippets.

@Nilegfx
Last active February 22, 2021 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nilegfx/20f4f818602391c28cc347892a0f2aae to your computer and use it in GitHub Desktop.
Save Nilegfx/20f4f818602391c28cc347892a0f2aae to your computer and use it in GitHub Desktop.

new javascript interview challenges.

Challange 0: Tell the truth Write a function that returns the number of truthy values in a given array. Return 0 if given an empty array.
// Examples
countTruthy([true, false, false, true, false]) // ➞  2
countTruthy([false, false, false, false]) // ➞  0
countTruthy([]) // ➞ 0
Challenge 1: Count Syllables Create a function that counts the number of syllables a word has. Each syllable is separated with a dash `-`.

Examples

numberSyllables("buf-fet")  2
numberSyllables("beau-ti-ful")  3
numberSyllables("mon-u-men-tal")  4
numberSyllables("on-o-mat-o-poe-ia")  6
Challenge 2: The Fizz Buzz Test Write a method that returns an array of all the numbers from 1 to an integer argument. But for multiples of three use “Fizz” instead of the number and for the multiples of five use “Buzz”. For numbers which are multiples of both three and five use “FizzBuzz”.

Examples

fizzBuzz(10)  [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz"]
fizzBuzz(15)  [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz"]
Challenge 3: Reverse the Odd Length Words Given a string, reverse all the words which have odd length. The even length words are not changed.

Examples

reverseOdd("Bananas")  "sananaB"

reverseOdd("One two three four")  "enO owt eerht four"

reverseOdd("Make sure uoy only esrever sdrow of ddo length")
 "Make sure you only reverse words of odd length"
Challenge 4: Find the Second Largest Number Create a function that takes an array of numbers and returns the second largest number.

Examples

secondLargest([10, 40, 30, 20, 50])  40

secondLargest([25, 143, 89, 13, 105])  105

secondLargest([54, 23, 11, 17, 10])  23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment