MCPcopy Create free account
hub / github.com/dailydotdev/apps / nearestLevelUp

Function nearestLevelUp

packages/webapp/components/world/ladder.ts:215–240  ·  view source on GitHub ↗
(
  rows: readonly LadderRow[] | undefined,
)

Source from the content-addressed store, hash-verified

213 * from a rung, the one further along is the one they are actually reading.
214 */
215export const nearestLevelUp = (
216 rows: readonly LadderRow[] | undefined,
217): NearestLevelUp | null => {
218 if (!rows?.length) {
219 return null;
220 }
221
222 let best: NearestLevelUp | null = null;
223 rows.forEach((row) => {
224 const progress = levelProgress(row.reads);
225 // Topped out: there is no next rung to walk towards.
226 if (!progress.next) {
227 return;
228 }
229 if (
230 best &&
231 (progress.toNext > best.toNext ||
232 (progress.toNext === best.toNext && row.reads <= best.reads))
233 ) {
234 return;
235 }
236 best = { ...row, ...progress, next: progress.next };
237 });
238
239 return best;
240};

Callers 2

useWorldLogFunction · 0.90
ladder.spec.tsFile · 0.90

Calls 1

levelProgressFunction · 0.85

Tested by

no test coverage detected