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
1var reversed = array.map(function reverse(item) {
2 return Array.isArray(item) && Array.isArray(item[0])
3 ? item.map(reverse)
4 : item.reverse();
5});
1let array1 = ["yes", "no", "maybe", "always", "sometimes", "never", "if"];
2let array2 = [5,8,2,9,5,6,3,1];
3
4function reverseArray(arr) {
5 var newArray = [];
6 for (var i = arr.length - 1; i >= 0; i--) {
7 newArray.push(arr[i]);
8 }
9 return newArray;
10}
11
12reverseArray(array1); // ["if", "never", "sometimes", "always", "maybe", "no", "yes"]
13reverseArray(array2); // [1, 3, 6, 5, 9, 2, 8, 5]