// Define an array of numbers const numbers = [4, 2, 5, 1, 3]; console.log("Original Numbers:", numbers); // Sort numbers in ascending order numbers.sort((a, b) => a - b); console.log("Sorted Numbers (Ascending):", numbers); // Reverse the sorted numbers const reversedNumbers = [...numbers].reverse(); console.log("Reversed Numbers:", reversedNumbers); // Define an array of fruits const fruits = ["Banana", "Orange", "Apple", "Mango"]; console.log("Original Fruits:", fruits); // Sort fruits alphabetically fruits.sort(); console.log("Sorted Fruits:", fruits); // Reverse the sorted fruits const reversedFruits = [...fruits].reverse(); console.log("Reversed Fruits:", reversedFruits); //OUTPUT Original Numbers: [4, 2, 5, 1, 3] Sorted Numbers (Ascending): [1, 2, 3, 4, 5] Reversed Numbers: [5, 4, 3, 2, 1] Original Fruits: ["Banana", "Orange", "Apple", "Mango"] Sorted Fruits: ["Apple", "Banana", "Mango", "Orange"] Reversed Fruits: ["Orange", "Mango", "Banana", "Apple"]
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter