MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / getNext

Function getNext

javascript/0202-happy-number.js:19–29  ·  view source on GitHub ↗
(n, sum = 0)

Source from the content-addressed store, hash-verified

17};
18
19var getNext = (n, sum = 0) => {
20 while (0 < n) {
21 /* Time O(log(N)) */
22 const remainder = n % 10;
23
24 n = Math.floor(n / 10);
25 sum += remainder * remainder;
26 }
27
28 return sum;
29};
30
31/**
32 * Hash Set - seen static

Callers 1

isHappyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected