Advertisement
Spocoman

07. Equal Arrays

Jan 20th, 2022
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arrOne, arrTwo) {
  2.  
  3.     if (arrOne.every(item => arrTwo.includes(item))) {
  4.         console.log(`Arrays are identical. Sum: ${arrOne.map(Number).reduce((a, b) => a + b, 0)}`);
  5.     } else {
  6.         for (let i = 0; i < arrOne.length; i++) {
  7.             if (arrOne[i] !== arrTwo[i]) {
  8.                 console.log(`Arrays are not identical. Found difference at ${i} index`);
  9.                 break;
  10.             }
  11.         }
  12.     }
  13. }
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement