Advertisement
makispaiktis

DCP4 - Missing integer

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