r/javaScriptStudyGroup • u/ForScale • May 10 '16
CHALLENGE: Write a multiplication function...
CHALLENGE:
Write a multiplication function that takes two numbers integers as arguments and returns their product.
Rules:
Cannot use
*or/operatorsCannot use Math object
Cannot use for (any variation) or while (including do) loops
2
Upvotes
2
u/Volv May 10 '16 edited May 10 '16
Nice. straight for the recursion. I see what you mean about lack of array.fill :) It is another new ES6 thing and according to this doesn't work natively in IE atm. yay babel.
We have pretty similar answers for both it seems. Main difference in second one is you carrying the result (and iteration info) in a closure over main function instead of threaded through the function calls.
Success tho - Only issue is your first solution will fail for negative values of a.. but having said that mine fails for negative y :)