Created
February 2, 2017 07:47
-
-
Save blessdyb/61896a6388e0768c784542e400a1d8ff to your computer and use it in GitHub Desktop.
Double all elements of array without array helper methods
This file contains 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
const numbers = [1, 2, 3]; | |
function double(num) { | |
let [firstNumber, ...restNumbers] = num; | |
if (firstNumber) { | |
return [2 * firstNumber, ...(double(restNumbers))]; | |
} else { | |
return []; | |
} | |
} | |
double(numbers); | |
/// [ 2, 4, 6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment