I would prefer to start with removing duplications from an array and then try to sort.Return the 1st element from new array.
function processData(myArray) { var s = new Set(myArray); var arr = [...s]; return arr.sort((a,b) => b-a)[1]; } console.log(processData([2,3,6,6,5]);