If we take the array [10, 5, 20] as our input, according to my function, the output should be [2, 3, 1]. This is because 10 is the second largest number, 5 is the third largest, and 20 is the largest.
function determineRankings(arr){
const result=[];
let newArr=arr.sort((a,b)=>b-a);
for (let i=0;i<arr.length;i++){
for (let j=0;j<newArr.length;j++){
arr[i]===newArr[j]? result.push(j+1): console.log('');
}
}
return(result);
}
When using my function with the input array of [10,5,20], I get the output [1,2,3], however the expected output is: rankings([10, 5, 20]); // [2, 3, 1] rankings([6, 8, 1, 12, 4, 3, 9]); // [4, 3, 7, 1, 5, 6, 2]