Skip to content

Instantly share code, notes, and snippets.

@kreas
Last active August 29, 2015 14:18
Show Gist options
  • Save kreas/8fba0ba7f472294b44fa to your computer and use it in GitHub Desktop.
Save kreas/8fba0ba7f472294b44fa to your computer and use it in GitHub Desktop.

Javascript Assessment

To complete this assessment, create a Github Gist for each tasks below. Once completed, please email a link for each Gist to [email protected].

This assessment was designed to help evaluate your knowledge of the core Javascript language. Please do not use any libraries such as jQuery of Underscore.

  1. Create a function called fizzBuzz that takes an integer (n). The function should loop over each number between 1 and n and prints "Fizz" if the number is divisible by 3, "Buzz" if the number is divisible by 5, "FizzBuzz" if the number is divisible by 3 and 5, and if the number is not divisible 3 or 5, it should print the number.

  2. Create a function called flipCoin that takes no parameters and randomly returns the string 'heads' or 'tails'. Create a second function called flipCoinResults that takes an integer n and runs flipCoin n times. flipCoinResults should return a string that represents the distribution of heads and tails for a given request.

  3. If we list all of the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6, and 9. The sum of these multiples is 23. Create a function called sumOfMultiples that replicates this behavior. sumOfMultiples should take one parameter that represents the maximum number (e.g. 1000).

  4. Currying allows you to easily create custom functions by partially invoking an existing function. Extend the Function's prototype to add a .curry function, and then show an example how .curry could be used. Keep in mind that even though currying is similar to closures, they are not the same thing.

  5. Create a function called highlightArticles that takes a string as its parameter. An example function call would be highlightArticles("The quick brown fox jumped over the lazy dog"). In your function, highlight all of the definite and indefinite articles, making the definite articles highlighted in yellow and the indefinite articles highlighted in blue.

  6. Extra credit: Create a function that takes an array of x and y coordinates. Assuming that the first element in the array is the starting point and the last element in the array is the ending point, return an array of x and y coordinates that represents the shortest possible route one could take to hit every point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment