Advertisement
teofarov13

Untitled

Jan 26th, 2023
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function equalArrays(arr, arr1) {
  2.      let sum = 0;
  3.  
  4.      for (let i = 0; i <= arr.length - 1; i++) {
  5.           if ((arr[i] = Number(arr[i])) == (arr1[i] = Number(arr1[i]))) {
  6.                sum = arr[i] + arr1[i];
  7.                if (i == arr.length-1) {
  8.                     console.log(`Arrays are identical. Sum: ${sum}`);
  9.                }
  10.           } else if ((arr[i] = Number(arr[i])) !== (arr1[i] = Number(arr1[i]))){
  11.                
  12.                console.log(`Arrays are not identical. Found difference at ${i} index`);
  13.                break;
  14.           }
  15.  
  16.      }
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement