1// Function to reverse Number
2function reverseNum(n) {
3 let r = n.toString().split('').reverse().join('');
4 return Math.sign(n) * parseInt(r);
5}
6
7// Call
8reverseNum(-267);
9reverseNum(31522);
10
11// Outputs
12-762
1322513
1var arr = [34, 234, 567, 4];
2print(arr);
3var new_arr = arr.reverse();
4print(new_arr);
5
1const array1 = [1,2,3,4];
2console.log('array1:', array1);
3//"array1:" Array [1, 2, 3, 4]
4
5const reversed = array1.reverse();
6console.log('reversed:', reversed);
7//"reversed:" Array [4, 3, 2, 1]
8
9// Careful: reverse is destructive -- it changes the original array.
10console.log('array1:', array1);
11//"array1:" Array [4, 3, 2, 1]
1var reversed = array.map(function reverse(item) {
2 return Array.isArray(item) && Array.isArray(item[0])
3 ? item.map(reverse)
4 : item.reverse();
5});