FastPrepFirst Promise to Settle
Problems/First Promise to Settle

First Promise to Settle

Rippling logoRippling● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Every rule here is our choice. The new promise copies whichever item settles first, a fulfilled value or a rejection reason. A plain value counts as ready, an object with a then method counts as a promise, and among items that are already settled the earlier one in the array wins. Later results are ignored and an empty array never settles. The fake clock, the step format, the tests and the examples are ours too.

One report, from an SDE2 screening round, lists writing this by hand among a group of small function tasks and says it took a minute. It gives no signature, no rule for plain values and no rule for an empty list.

This version records when and how the new promise settles. It cannot read your code, so the explanation side is in the editorial.

Our version is about 50% the same as the reported question.

Write firstSettled(items). items is an array. Each item is a promise or any other value. Return a new promise that settles the same way as the first item to settle: if that item fulfills with a value, so does the new promise, and if it rejects with a reason, so does the new promise. Do not use Promise.race (the tests cannot check this; the point is to build it yourself).

Rules for this exercise:

  • An item that is not a promise counts as ready at once with that value, and an object with a then method counts as a promise.
  • Plain values and promises that are already settled when you get them are taken in array order: the first of them wins.
  • Items that settle later are ignored, and their results never change the new promise.
  • If items is empty, the new promise never settles.

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. The name solution is the function you write. A name like "obj.method" calls the method with obj 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, await and state step, in order: {"returns": value} or {"throws": "ErrorName"}. A function is written {"$function": true} and undefined is written {"$undefined": true}.

Tests use fake time. resolveAfter(ms, value) makes a promise that fulfills with value after ms time units, and rejectAfter(ms, reason) makes one that rejects. {"tick": ms} moves the clock forward. {"await": "p"} moves the clock until p settles and records {"resolves": value, "at": time} or {"rejects": reason, "at": time}, or {"pending": true, "at": time} if it never settles. {"state": "p"} records the state without moving the clock: {"pending": true}, {"resolved": value} or {"rejected": reason}. A promise is written {"$promise": true} and an error {"$error": "Error", "message": "..."}. Each test starts at time 0 and runs at once.

Function

firstSettled(steps: JsSteps) → JsStepResults

Examples

Example 1

steps = [{"let":"tea","value":{"$js":"resolveAfter(80, 'tea')"}},{"let":"coffee","value":{"$js":"resolveAfter(30, 'coffee')"}},{"call":"solution","args":[[{"$js":"tea"},{"$js":"coffee"}]],"let":"r"},{"state":"r"},{"tick":29},{"state":"r"},{"await":"r"}]return = [{"returns":{"$promise":true}},{"pending":true},{"pending":true},{"resolves":"coffee","at":30}]
  • tea fulfills at time 80 and coffee at time 30. firstSettled returns a promise r.
  • Right away, r is pending. At time 29 it is still pending.
  • Waiting for r takes the clock to 30, when coffee fulfills: r fulfills with "coffee" at 30. The later tea is ignored.

Example 2

steps = [{"let":"slow","value":{"$js":"resolveAfter(60, 'ok')"}},{"let":"bad","value":{"$js":"rejectAfter(20, new Error('offline'))"}},{"call":"solution","args":[[{"$js":"slow"},{"$js":"bad"}]],"let":"r"},{"await":"r"}]return = [{"returns":{"$promise":true}},{"rejects":{"$error":"Error","message":"offline"},"at":20}]
  • slow would fulfill at 60, but bad rejects at 20 with the error offline.
  • The first to settle is bad, so r rejects with that error at 20.

Example 3

steps = [{"let":"slow","value":{"$js":"resolveAfter(30, 'a')"}},{"call":"solution","args":[[{"$js":"slow"},5]],"let":"r"},{"await":"r"}]return = [{"returns":{"$promise":true}},{"resolves":5,"at":0}]
  • The first item is a promise that would fulfill at 30. The second item is the plain number 5, which is ready at once.
  • So r fulfills with 5 at time 0.

Constraints

  • items has 0 to 5 entries
  • Each test has 2 to 7 steps, and times are whole numbers from 0 to 1000

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

  • Timer Job Scheduler Wake-upsRedNote · PHONE SCREEN
  • Rank-Based Cache with a Data SourceLinkedIn · PHONE SCREENLinkedIn interview questions
  • Concurrent Token-Bucket Rate LimiterCharta Health · PHONE SCREENCharta Health interview questions
  • Ordered Number Printing with Three ThreadsArize AI · PHONE SCREEN
  • Bounded Service Instance RegistryRevolut · PHONE SCREENRevolut interview questions
  • Modal Lock and Fair Modal LockOpenAI · PHONE SCREENOpenAI interview questions
  • Course Ordering with Concurrent UpdatesNuro · PHONE SCREENNuro interview questions
  • Single-Flight Chunk CacheModal Learning · PHONE SCREEN
  • Thread-Safe Request Counts by AttributeRubrik · ONSITE INTERVIEWRubrik interview questions
  • Thread-Safe Concurrent Linked ListApple · ONSITE INTERVIEWApple interview questions

Interview reports that mention this question

  • Rippling Frontend, Mobile, Data: 18 Experiences (Part 12 of 12)

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)
All Rippling interview questionsSee Rippling hiring insights
Saved
Checking account…