Skip to content

Instantly share code, notes, and snippets.

@lienista
Last active August 28, 2018 04:07
Show Gist options
  • Select an option

  • Save lienista/c4344bf80b7009ea7c4798a3dcb26364 to your computer and use it in GitHub Desktop.

Select an option

Save lienista/c4344bf80b7009ea7c4798a3dcb26364 to your computer and use it in GitHub Desktop.
const recursiveMultiplier = (arr, num) => {
let newArray = [];
let mult = function(a) {
if(a.length) {
newArray[a.length-1] = a.pop()*num;
mult(a);
return newArray;
}
return;
}
return mult(arr);
}
let x = [1, 2, 3], num = 2;
let y = recursiveMultiplier(x,num);
console.log(y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment