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

Prison Break: A Simple Counting Problem

Imagine a prison having 36 cells arranged like the squares in a 6-by-6 grid. All adjacent cells have doors between them; doors that you can open. You, the prisoner in the top-left corner cell, are told that you can have your freedom if... Continue →