MCPcopy Create free account
hub / github.com/careercup/CtCI-6th-Edition-JavaScript / next

Function next

chapter05/5.4 - Next Number/nextNumber.js:8–14  ·  view source on GitHub ↗
(number, numOnes, iterator)

Source from the content-addressed store, hash-verified

6};
7
8var next = function(number, numOnes, iterator) {
9 var currNum = iterator(number);
10 while (countOnes(currNum.toString(2)) !== numOnes) {
11 currNum = iterator(currNum);
12 }
13 return currNum;
14};
15
16var nextSmallest = function(number, numOnes) {
17 return next(number, numOnes, currNum => currNum - 1);

Callers 2

nextSmallestFunction · 0.85
nextLargestFunction · 0.85

Calls 1

countOnesFunction · 0.85

Tested by

no test coverage detected