Ivankooo1

Equal Arrays

Aug 20th, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function diffArrays(arr1,arr2){
  2.  
  3.     let sum = 0;
  4.     let notEqual = true;
  5.  
  6.   for(let i = 0; i < arr1.length;i++){
  7.       arr1[i] = Number(arr1[i]);
  8.       sum += arr1[i];
  9.   }
  10.  
  11.  
  12.   for(let i = 0;i < arr2.length;i++){
  13.       arr2[i] = Number(arr2[i]);
  14.   }
  15.  
  16.   for(let i = 0; i < arr1.length;i++){
  17.  
  18.   if(arr1[i] !== arr2[i]){
  19.     console.log(`Array are not indetical.Found difference at ${i} index. `);
  20.     notEqual = false;
  21.     break;
  22.   }
  23.  
  24.  }
  25.  if(notEqual){
  26.     console.log(`Arrays are identical.Sum: ${sum}`);
  27.   }
  28. }
  29.  diffArrays(['1','2','3','4','5'],['1','2','4','4','5'])
Advertisement
Add Comment
Please, Sign In to add comment