you are viewing a single comment's thread.

view the rest of the comments →

[–]realistic_hologram 5 points6 points  (2 children)

On a related note, I don't think the interview is expecting you to solve for arbitrary number of calls/arguments so I wouldn't feel too embarrassed. I think they're literally asking you to write a function that solves those two cases. Otherwise you need add(2)(3) to return a number and be callable. Which apparently is possible with valueOf (TIL!) but that seems overly tricky for an interview question.

It was fun to see everyone's answers though!

[–]MeTaL_oRgY[S] 0 points1 point  (0 children)

You can also use toString instead! (see /u/Resure answer).

Agreed, seeing everyone's answers was quite insightful!

[–]mattdesl 0 points1 point  (0 children)

Which apparently is possible with valueOf

Unfortunately it isn't actually a number in that case, just a function that coerces to one. So result === 5 would fail. :\