1 개요[ | ]
- 함수 ranks()
2 JavaScript[ | ]

JavaScript
Copy
function ranks(arr) {
const sorted = arr.slice().sort(function(a,b){return b-a});
return arr.slice().map(function(v){ return sorted.indexOf(v)+1 });
}
console.log( ranks([79, 5, 18, 18, 32]) ); // [1, 5, 3, 3, 2]
▶ | [1, 5, 3, 3, 2] |
3 PHP[ | ]

PHP
Copy
function ranks($arr) {
$sorted = $arr;
rsort($sorted);
return array_map(function($v) use ($sorted) { return array_search($v,$sorted)+1; },$arr);
}
print_r( ranks([79, 5, 18, 18, 32]) );
Loading
4 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.