Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Problem 6. Is Array Symmetric
- Write a program that finds if an array of numbers is symmetric - that is, the first number is equal to the last, the second - to the second last and so on
- Examples:
- Input Output
- 1 2 3 4 4 3 2 1 Yes
- Input Output
- 7 8 9 8 7 Yes
- Input Output
- 3 4 5 3 4 5 No
- */
- input = [
- '1 2 3 4 4 3 2 1'
- // '7 8 9 8 7'
- // '3 4 5 3 4 5'
- ];
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- const array = gets().split(' ');
- let result = 'Yes'
- for (let i = 0; i <= (array.length - 1) / 2; i++) {
- if (array[i] !== array[array.length - 1 - i]) {
- result = 'No';
- break;
- }
- }
- console.log(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement