Last active
September 20, 2019 12:18
-
-
Save kylejeske/741310e01493309d34314ab9b43dad18 to your computer and use it in GitHub Desktop.
Double Numbers using Recursion in JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* double-numbers.js | |
* | |
* Translates an Array of Numbers to Double that using Recursion and some ES6 tricks. | |
* @some(techniques).included([expansion assignment, rest operator, spread operator, ternary operator, arrow functions]) | |
*/ | |
((numbers=[]) => { | |
const doubleNumbers = ( collection = [], [ head, ...tail ] = collection ) => | |
(collection.length === 0) | |
? [] | |
: [].concat([head * 2], doubleNumbers(tail)) | |
console.log(`Start with ${numbers.toString()}, and End with ${(doubleNumbers(numbers)).toString()}`); | |
})([2,4,6,8]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment