silvana1303

equal arrays

Apr 7th, 2021
345
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function  solve(arr1, arr2){
  2.  
  3.     let sumArr = [];
  4.  
  5.     for (let i = 0; i <arr1.length ; i++) {
  6.  
  7.         if (arr1[i] == arr2[i]){
  8.             let number = Number(arr1[i]);
  9.             sumArr.push(number);
  10.         } else {
  11.             console.log(`Arrays are not identical. Found difference at ${i} index`);
  12.             break;
  13.         }
  14.     }
  15.  
  16.     if (sumArr.length == arr1.length){
  17.         let sum = sumArr.reduce((a, b) => a + b);
  18.         console.log(`Arrays are identical. Sum: ${sum}`)
  19.     }
  20.  
  21.  
  22. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×