Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
Get item with max score React

I have data that returning from BE

Here is code where I show it

<div className="pr-0 mt-20" style={{ display: 'flex', justifyContent: 'center' }}>
      <MuiCardWithAnimation component={AnimateSimple} recipe="slideRightInLarge" className="w-6/12  mx-auto m-16 md:m-0" square>
        <CardContent className="flex flex-col items-center justify-center p-32 md:p-48 md:pt-128 ">
          <Typography variant="h6" className="md:w-full mb-32">
            Result
          </Typography>

          {companiesHouseResults?.filter(r => Math.max(r.matchConfidenceScore)).map((r) => (
            <div className="col col-lg-4 grid-wrapper">
              <Card sx={{ minWidth: 275 }}>
                <CardContent>
                  <Typography variant="h5" component="div">
                    Company Name: {r.companyName}
                  </Typography>
                  <Typography sx={{ mb: 1.5 }}>Confidence Band: {r.matchConfidenceBand}</Typography>
                  <Typography variant="body2">Confidence Score: {r.matchConfidenceScore}</Typography>
                </CardContent>
              </Card>
            </div>
          ))}
        </CardContent>
      </MuiCardWithAnimation>
    </div>

Here {companiesHouseResults?.filter(r => Math.max(r.matchConfidenceScore)).map((r) I need to filter it to get element with highest score

But at Math.max I got this error

Argument of type 'number | undefined' is not assignable to parameter of type 'number'. Type 'undefined' is not assignable to type 'number'.

How I can solve this?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need to check if it is undefined before passing it to Math.max function, you can do it for example like this

r.matchConfidenceScore && Math.max(r.matchConfidenceScore)

Value of r.matchConfidenceScore will be cast to boolean, and if it is false it will not execute the next statement because of the logical AND (&&)

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can sort your items by the score and got first one.

const el = companiesHouseResults.sort(
  (a, b) => a.matchConfidenceScore - b.matchConfidenceScore
)[0];
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda