Advertisement
CR7CR7

symmetry-array

Sep 18th, 2022
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let array = [2, 4, 6, 6, 3, 2];
  2. let length = array.length;
  3.  
  4. let isSymmetric = true;
  5.  
  6. for (let i = 0; i < length / 2; i++) {
  7.   if (array[i] !== array[length - i - 1]) {
  8.     isSymmetric = false;
  9.     break;
  10.   }
  11. }
  12.  
  13. console.log(`The array is symmetric: ${isSymmetric}`);
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement