Skip to content

Instantly share code, notes, and snippets.

@rofr
Last active November 29, 2017 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rofr/8215617f1f92555722ee4316292aba3a to your computer and use it in GitHub Desktop.
Save rofr/8215617f1f92555722ee4316292aba3a to your computer and use it in GitHub Desktop.
Recursive implementation of silly FB challenge
function funkyProduct(list, leftProduct = 1) {
if (list.length === 0) return [1];
else {
var result = funkyProduct(list.slice(1), leftProduct * list[0]);
var rightProduct = result[0] * list[0];
result[0] *= leftProduct;
if (leftProduct > 1) result.unshift(rightProduct);
return result;
}
}
funkyProduct([2,3,5,10])
//results in: [150,100,60,30]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment