Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
return the index of new shuffled element

Here is what I want:

I have first array and I have the index as below:

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

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

In the first array the index points to the second element in the array which is b right?

Now I shuffled the first array and we have the shuffled array .

The index of b is 2 right now. I want to return this new index...

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use,

Let value = first[index]

let newValue =shuffled.indexof(value)

about 4 years ago · Juan Pablo Isaza Relatório

0

you can use shuffled.indexOf(first[index])

first[index] returns the value of the first index in this case 'b'

shuffled.indexOf('b') would return the index of b in the shuffled array

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda