r/javaScriptStudyGroup • • 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:

  1. Cannot use * or / operators

  2. Cannot use Math object

  3. Cannot use for (any variation) or while (including do) loops

2 Upvotes

17 comments sorted by

View all comments

2

u/Volv May 10 '16 edited May 10 '16

Not gonna look at yours for a bit cause there must be more ways to do this.
Do you consider this cheating? :)

1

u/ForScale May 10 '16

Nice! I came up with two ways to do it. Both use a similar approach to avoid loops, but one uses a predefined method where the other does not.

I don't consider a blank Pen to be cheating, but I also don't consider it to be a valid answer! ;) I think you forgot to click save...

2

u/Volv May 10 '16

How about this

1

u/ForScale May 10 '16

Aha! No, I don't consider that cheating. That fill method... nice!! Wait till you see my solutions, the first one certainly could have used fill. Thanks for the heads-up on it!

And whats the 0 argument in the reduce function? Is that starting index?

2

u/Volv May 10 '16

yep, exactly.

1

u/ForScale May 10 '16

Cool. Nice work with the challenge and the one-liner! It just came to me for some reason so I thought I'd post it here. Let me know your thoughts on my solution when you get a chance! Obviously no rush or anything.