var arrayRankTransform = function(arr) { let tempArr = JSON.parse(JSON.stringify(arr)) arr.sort() let arrObj = {} arr.forEach((item, index) => { if () { } else { arrObj[item] = index+1 } }) for(let i=0;i<tempArr.length;i++){ tempArr[i] = arrObj[tempArr[i]] } return tempArr }; console.log(arrayRankTransform([100, 100, 100])) // console.log(arrayRankTransform([37,12,28,9,100,56,80,5,12]))