I have a code that count sportsmens rating , for example if you have same rating as person before you will have same score number :
import "./styles.css";
export default function App() {
const ratingScore = [100, 90, 90, 90, 80, 70, 60, 50, 50, 50, 50, 40];
const getRatingNum = (rating) => {
const ratingScore = [];
rating.forEach((el, i, arr) => {
if (i === 0) {
ratingScore.push(1);
return;
}
if (arr[i - 1] > el) {
const newScore = ratingScore.at(-1) + 1;
ratingScore.push(newScore);
return;
}
if (arr[i - 1] === el) {
const newScore = ratingScore.at(-1);
ratingScore.push(newScore);
return;
}
});
return ratingScore;
};
return (
<div className="App">
{ratingScore.map((el, i) => {
return (
<p key={Math.random() * 10}>
{getRatingNum(ratingScore)[i]}. {el}
</p>
);
})}
</div>
);
}
link to live example - https://codesandbox.io/s/happy-williams-2s5dz?file=/src/App.js
Is there a better approach to count sportsmens rating?