• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

205
Views
devolver el índice del nuevo elemento barajado

Esto es lo que quiero:

Tengo la first matriz y tengo el index de la siguiente manera:

 const first = ['a','b','c']; const index = 1; // the index of b const shuffled = ['c','a','b']; // now the index of b is 2

En la first matriz, el index apunta al segundo elemento de la matriz, que es b , ¿verdad?

Ahora mezclé la first matriz y tenemos la matriz shuffled .

El índice de b es 2 en este momento. Quiero devolver este nuevo índice...

almost 3 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Usando Array#indexOf :

 const first = ['a','b','c']; const index = 1; const shuffled = ['c','a','b']; const target = first[index]; const newIndex = shuffled.indexOf(target); console.log(newIndex);

almost 3 years ago · Juan Pablo Isaza Report

0

Puedes usar,

Sea valor = primero[índice]

let newValue =shuffled.indexof(valor)

almost 3 years ago · Juan Pablo Isaza Report

0

puedes usar shuffled.indexOf(first[index])

first[index] devuelve el valor del first index en este caso 'b'

shuffled.indexOf('b') devolvería el índice de b en la matriz shuffled

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error