Skip to content

Instantly share code, notes, and snippets.

@Nilegfx
Last active September 26, 2020 13:43
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/2831f27d34d7b66b8fd48efcf7470ec4 to your computer and use it in GitHub Desktop.
Save Nilegfx/2831f27d34d7b66b8fd48efcf7470ec4 to your computer and use it in GitHub Desktop.

javascript interview challenges

Challange 1: 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

Challange 2: Double bubble

Create a function that takes two numbers as arguments (num, steps) that returns an array of multiples of num up to the steps. for example

arrayOfMultiples(1, 2); // ➞  means [1*1, 1*2] = [1, 2]
arrayOfMultiples(20, 3); // ➞  means [20*1, 20*2, 20*3] = [20, 40, 60]
arrayOfMultiples(7, 5); // ➞ [7, 14, 21, 28, 35]
arrayOfMultiples(12, 10); // ➞ [12, 24, 36, 48, 60, 72, 84, 96, 108, 120]
arrayOfMultiples(17, 6); // ➞ [17, 34, 51, 68, 85, 102]

Challange 3: Add up

Write a function that takes a number as an argument. Add up all the numbers from 1 to that number. For example, if the input is 4 then your function should return 10 because 1 + 2 + 3 + 4 = 10.

Examples

addUp(4); // ➞ 10  

addUp(13); // ➞ 91

addUp(600); // ➞ 180300

Challange 4: Hide and seek

A word is on the loose and now has tried to hide amongst a crowd of tall letters! Help write a function to detect what the word is, knowing the following rules:

  • The wanted word is in lowercase.
  • The crowd of letters is all in uppercase.
  • the word will be spread out amongst the random letters, but their letters remain in the same order.

Examples

detectWord("UcUNFYGaFYFYGtNUH"); // ➞ "cat"
detectWord("bEEFGBuFBRrHgUHlNFYaYr"); // ➞ "burglar"
detectWord("YFemHUFBbezFBYzFBYLleGBYEFGBMENTment"); // ➞ "embezzlement"

Challange 5: Family budget

Create the function that takes an array with objects and returns the sum of people's budgets.

Examples

getBudgets([
  { name: "father", age: 32, budget: 23000 },
  { name: "mother",  age: 29, budget: 40000 },
  { name: "son",  age: 16, budget: 2700 }
]); // ➞ 65700

getBudgets([
  { name: "John",  age: 21, budget: 29000 },
  { name: "Steve",  age: 32, budget: 32000 },
  { name: "Martin",  age: 16, budget: 1600 }
]); // ➞ 62600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment