Fix the Receiver and First Arguments of a Function
Updated
Problem statement
Add a method presetBind(receiver, ...first) to Function.prototype, so every function can call it. It returns a new function. Do not use the built-in bind (the tests cannot check this; the point is to build it yourself).
Let target be the function that presetBind was called on. When the new function is called with later arguments:
- Called normally: run
targetwiththisset toreceiverand with the argumentsfirstfollowed bylater, and return its result. Thethisof the new call is ignored. - Called with
new: runtargetas a constructor with the argumentsfirstfollowed bylater, and give back whatnew target(...)gives back.receiveris ignored. The object it makes must still be an instance oftarget.
Rules for this exercise:
- If
presetBindis called on something that is not a function, throw aTypeError. - A function made by
presetBindcan callpresetBindagain. The firstreceiverstays, and the new preset arguments go after the earlier ones. - Each call to
presetBindreturns a separate function. The name andlengthof the new function are not tested. - An arrow function can be wrapped and called normally. Calling the wrapper with
newthen throws aTypeError, as it does for the arrow function.
How the tests are written
Each test is a short script: a list of steps that run in order. {"let": "x", "value": V} makes a value called x. A value written as {"$js": "expression"} is the result of that JavaScript expression, and the expression may use names made earlier. {"call": "f", "args": [...]} calls f. A name like "add.presetBind" calls the method presetBind that you write, with add as this. An optional "this" sets this for the call, an optional "new": true calls it with new, and an optional "let" saves the result under a name.
The expected output has one entry for each call, in order: {"returns": value} or {"throws": "ErrorName"}. A function is written {"$function": true} and undefined is written {"$undefined": true}. A plain object result is written as JSON, such as {"sum": 7}. An object made by a constructor is written {"$instance": "Pair", "fields": {...}}: the constructor's name and the object's own fields. Object results are compared by that name and those fields.
Function
presetBind(steps: JsSteps) → JsStepResultsExamples
Example 1
steps = [{"let":"obj","value":{"x":10}},{"let":"add","value":{"$js":"function (a, b) { return this.x + a + b; }"}},{"call":"add.presetBind","args":[{"$js":"obj"},1],"let":"bound"},{"call":"bound","args":[2]},{"call":"bound","args":[5],"this":{"x":100}}]return = [{"returns":{"$function":true}},{"returns":13},{"returns":16}]addreturnsthis.x + a + b.add.presetBind(obj, 1)returns a functionbound.bound(2)runsaddwiththis=obj(wherexis 10) and the arguments 1, 2: 10 + 1 + 2 = 13.- The next call passes its own
thiswithx= 100, but that is ignored.bound(5)gives 10 + 1 + 5 = 16.
Example 2
steps = [{"let":"Pair","value":{"$js":"function Pair(left, right) { this.left = left; this.right = right; }"}},{"call":"Pair.presetBind","args":[null,"L"],"let":"P"},{"call":"P","args":["R"],"new":true,"let":"p"},{"let":"isPair","value":{"$js":"(v) => v instanceof Pair"}},{"call":"isPair","args":[{"$js":"p"}]}]return = [{"returns":{"$function":true}},{"returns":{"$instance":"Pair","fields":{"left":"L","right":"R"}}},{"returns":true}]Pairstores its two arguments asleftandright.Pair.presetBind(null, 'L')returns a functionP.new P('R')runsPairas a constructor with the arguments'L'and'R'. The result is aPairwithleft="L"andright="R".- The check
p instanceof Pairistrue.
Example 3
steps = [{"let":"holder","value":{"$js":"{ presetBind: Function.prototype.presetBind }"}},{"call":"holder.presetBind","args":[null]}]return = [{"throws":"TypeError"}]holderis a plain object that has the method copied onto it.holder.presetBind(null)runs it withthis=holder, which is not a function.- So it throws a
TypeError:{"throws": "TypeError"}.
Constraints
- receiver is an object, null or a function value
- Each test has 2 to 8 steps, and every call has 0 to 5 arguments
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
- Per-Client API Rate LimiterDocker · PHONE SCREEN
- Read Across Sound TracksAirbnb · PHONE SCREENAirbnb interview questions
- Streaming Median of Trade PricesXantium · PHONE SCREEN
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Top K Pins with Insert and QueryPinterest · PHONE SCREENPinterest interview questions
Interview reports that mention this question
Rippling interview experiences
- Rippling No-Level Older Reports: 31 Experiences (Part 6 of 6)
- Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
- Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
- Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)
- Rippling No-Level Design, Screens: 30 Experiences (Part 2 of 6)