Javascript Weekly Challenge #1

Starting today, I plan on coming out with a new JavaScript challenge every week. These problems might look leisurely and pointless at the outset, but solving them should require intermediate-level language skills. Answers will be posted at the end of the week, one day before the next challenge comes out. Cheers!

How would you make the following work?

add(2, 5); // returns 7

add(2)(5); // returns 7

add(2)(5)(1, 3)(4); // returns 15

add(2)(5)(1, 3)(4)(1, 1, 2)(1)()(1, 1); // returns 22

DISCLAIMER I came across this problem while going through the very popular Front-end Job Interview Questions repo on Github. It caught my attention since I’d recently seen something similar in Angus Croll’s If Hemingway Wrote Javascript.


All queries and solutions (fiddles/pastebins) may be sent in via e-mail. Solutions may also be submitted by forking the Github repo.

 
13
Kudos
 
13
Kudos

Now read this

If Arundhati Roy wrote JavaScript

Angus Croll’s If Hemingway Wrote JavaScript is a beautifully illustrated book full of code snippets that are rich in their use of fundamental JavaScript abstractions and modern programming patterns. Born out of equal love for both... Continue →