Skip to content

Instantly share code, notes, and snippets.

@blessdyb
Created February 2, 2017 07:47
Show Gist options
  • Save blessdyb/61896a6388e0768c784542e400a1d8ff to your computer and use it in GitHub Desktop.
Save blessdyb/61896a6388e0768c784542e400a1d8ff to your computer and use it in GitHub Desktop.
Double all elements of array without array helper methods
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