1. Write a JavaScript function which will take an array of numbers stored and find the second lowest and second highest numbers, respectively.
Answers
Answered by
6
const secondLowest = arr => arr.sort((a, b) => a - b)[1]
const secondLargest = arr => arr.sort((a, b) => b - a)[1]
let arr = [365, 253, 755, 296, 108, 613, 334, 47, 623, 567]
console.log(`second lowest: ${secondLowest(arr)}\nSecond largest: ${secondLargest(arr)}`)
Similar questions