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

Function search

javascript/0041-first-missing-positive.js:29–40  ·  view source on GitHub ↗
(nums, index = 0)

Source from the content-addressed store, hash-verified

27};
28
29const search = (nums, index = 0) => {
30 while (index < nums.length) {
31 const num = nums[index];
32 const indexKey = index + 1;
33
34 if (!isEqual(num, indexKey)) return indexKey;
35
36 index += 1;
37 }
38
39 return nums.length + 1;
40};
41
42const canSwap = (nums, num, indexNum) =>
43 isPositive(num) && isInBound(num, nums) && !isEqual(num, indexNum);

Callers 1

firstMissingPositiveFunction · 0.70

Calls 1

isEqualFunction · 0.85

Tested by

no test coverage detected