const arr = [1, 2, 3, 4, 5];
const reversedArr = arr.reverse();

/* Reverses the order of elements in the array */
console.log(reversedArr); // Output: [5, 4, 3, 2, 1]

/* Modifies the original array in place */
console.log(arr); // Output: [5, 4, 3, 2, 1]
arr.reverse()
const originalArray = [1, 2, 3, 4, 5];

// Create a copy of the original array
const copiedArray = originalArray.slice();

// Apply the reverse() function to the copy
copiedArray.reverse();

console.log(originalArray); // [1, 2, 3, 4, 5] (the original array remains unchanged)
console.log(copiedArray);   // [5, 4, 3, 2, 1] (the array is reversed)
const originalArray = [1, 2, 3, 4, 5];

// Create a copy of the original array using the spread (...) syntax
const copiedArray = [...originalArray];

// Apply the reverse() function to the copy
copiedArray.reverse();

console.log(originalArray); // [1, 2, 3, 4, 5] (the original array remains unchanged)
console.log(copiedArray);   // [5, 4, 3, 2, 1] (the array is reversed)
const originalArray = [1, 2, 3, 4, 5];

/* Reverses the order of the elements in the array */
const reversedArray = originalArray.toReversed();

console.log(reversedArray); // [5, 4, 3, 2, 1] (the array is reversed)

/* The original array remains unchanged */
console.log(originalArray);   // [1, 2, 3, 4, 5]
const numbers = [1, 2, 3, 4, 5];

// Reverse the array order and print each element
numbers.reverse().forEach(number => {
    console.log(number);
});

// Output: 5, 4, 3, 2, 1
const str = "Hello, World!";

// Convert the string to an array, reverse it, then join it back to a string
const reversedStr = str.split("").reverse().join("");

console.log(reversedStr);
// Output: "!dlroW ,olleH"
const numbers = [1, 2, 3, 4, 5];

// Reverse the array and filter out the elements that meet a condition
const filteredNumbers = numbers.reverse().filter(number => number % 2 === 0);

console.log(filteredNumbers);
// Output: [4, 2]