Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
¿Hay un mejor enfoque para contar la calificación de los deportistas?

Tengo un código que cuenta la calificación de los deportistas, por ejemplo, si tiene la misma calificación que la persona anterior, tendrá el mismo número de puntuación:

 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> ); }

enlace al ejemplo en vivo: https://codesandbox.io/s/happy-williams-2s5dz?file=/src/App.js

¿Hay un mejor enfoque para contar la calificación de los deportistas?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

¿Qué pasa con un enfoque tan simple (pseudocódigo):

 let ratings = [1], curr_rating = 1 for (let i = 1; i < ratingScore.length; i++) { if ratingScore[i] < ratingScore[i - 1] { curr_rating++ } ratings.push(curr_rating) }
about 4 years ago · Juan Pablo Isaza Report

0

También puedes hacer como:

 const getRatingNum = ( rating ) => { let result = [], count = 0; ratingScore.forEach( ( n ) => { if (!result.length || result[result.length - 1].key !== n) result.push( { key: n, count: ++count } ); else result.push( { key: n, count: result[result.length - 1].count } ); } ); return result; };

Demo en vivo

Demostración de Codesandbox

 import React from 'react'; export default function App() { const ratingScore = [100, 90, 90, 90, 80, 70, 60, 50, 50, 50, 50, 40]; const getRatingNum = ( rating ) => { let result = [], count = 0; ratingScore.forEach( ( n ) => { if (!result.length || result[result.length - 1].key !== n) result.push( { key: n, count: ++count } ); else result.push( { key: n, count: result[result.length - 1].count } ); } ); return result; }; return ( <div className="App"> { getRatingNum(ratingScore).map((o, i) => { return ( <p key={i}>{o.count}. {o.key}</p> ) }) } </div> ); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!