Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findMissingInt(arr){
- i = 0;
- while(arr.indexOf(i) != -1){
- // If index is not -1, it will be another number, it means that this number eixsts
- i++;
- }
- return i;
- }
- // MAIN FUNCTION
- arr1 = [1, 2, 3, 7, 0];
- arr2 = [0, -1, -2, 3];
- arr3 = [-1, -2, -5]
- arr4 = [0, 3, 1, -9, 10, 2, 4, 6, 7, 5, 5]
- console.log();
- console.log(arr1 + " ----> missing int = " + findMissingInt(arr1));
- console.log(arr2 + " ----> missing int = " + findMissingInt(arr2));
- console.log(arr3 + " ----> missing int = " + findMissingInt(arr3));
- console.log(arr4 + " ----> missing int = " + findMissingInt(arr4));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement