Advertisement
CR7CR7

symm

Feb 6th, 2022
1,099
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //let input = [1, 2, 3, 4, 4, 3, 2, 1];//Yes
  2. //let input = [3,4,5,3,4,5];//No
  3. let input =[7,8,9,8,7] //Yes
  4. let print = this.print || console.log;
  5. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  6. let symmetric = true;
  7. let n =+gets();
  8.  
  9. // loop iterate up to the middle and compare first element with last element
  10. for(let i=0; i<n/2;i++){
  11.     if(input[i] != input[n-i-1]){
  12.         symmetric = false;
  13.        
  14.     }
  15.    
  16. }
  17. if (symmetric){
  18.     print('Yes');
  19. }
  20. else {
  21.     print('No');
  22. };
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement