Skip to content

Instantly share code, notes, and snippets.

@MikeDigitize
Created January 3, 2016 19:58
Show Gist options
  • Save MikeDigitize/605157a160bcb39c08a7 to your computer and use it in GitHub Desktop.
Save MikeDigitize/605157a160bcb39c08a7 to your computer and use it in GitHub Desktop.
Some coding challenges for the AO front end team who are learning JavaScript
// write a function that returns the sum of two numbers
// then modify it to...
// return the sum of three numbers
// then the first argument is an array of numbers
// then the first argument may or may not be an array
// then there are an unknown amount of numbers and arrays passed in
function add(...nums) {
return nums.reduce((a,b) => a.concat(b), []).reduce((a,b) => a+b, 0);
}
add(5,4,[4,4,4,4,4,4,4,4,4,4,4,4],[10,10,10,10],3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment