Created
July 30, 2019 03:51
-
-
Save wataruoguchi/4f1e511e707f9a6360f60c9fe3203fd7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://practice.geeksforgeeks.org/problems/missing-number-in-array/0 | |
function findMissingNum(arr) { | |
const res = arr.sort((a,b) => a - b).filter((num, idx) => { | |
return num !== idx + 1 | |
}); | |
return res.length ? res[0] - 1: -1; | |
} | |
const nums1 = [1,2,3,5]; | |
const result1 = findMissingNum(nums1); | |
console.log(result1 === 4); | |
const nums2 = [1,2,3,4,5,6,7,8,10]; | |
const result2 = findMissingNum(nums2); | |
console.log(result2 === 9); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment