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

155
Visualizações
Matriz de mapas de Javascript y luego compare claves si declaración

Tengo una matriz del alfabeto y 2 conjuntos de valores, estoy tratando de verificar si un valor está entre los 2 valores dados y luego imprimo la letra. Mi código:

 var alphabet_num = { "alphabet": ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"], "start": ["0", "150", "300", "450", "600", "750", "900", "1050", "1200", "1350", "1500", "1650", "1800", "1950", "2100", "2250"], "end": ["149", "299", "449", "599", "749", "899", "1049", "1199", "1349", "1499", "1649", "1799", "1949", "2099", "2249", "2399"] }; var xValue = 76; var result = alphabet_num.alphabet.map( (k, i) => [ k, alphabet_num.start[i], alphabet_num.end[i] if (xValue >= alphabet_num.start[i] && xValue <= alphabet_num.end[i]) { //a } ] );
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Si está buscando un valor específico, no necesita la función de map , puede resolverlo con find .

 const result = alphabet_num.alphabet.find( (_letter, i) => parseInt(alphabet_num.start[i]) <= xValue && xValue <= parseInt(alphabet_num.end[i]) );
about 4 years ago · Juan Pablo Isaza Relatório

0

 <script> var alphabet_num = { "alphabet": ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"], "start": ["0", "150", "300", "450", "600", "750", "900", "1050", "1200", "1350", "1500", "1650", "1800", "1950", "2100", "2250"], "end": ["149", "299", "449", "599", "749", "899", "1049", "1199", "1349", "1499", "1649", "1799", "1949", "2099", "2249", "2399"] }; var xValue = 350; var result = alphabet_num.alphabet.map( function(k, i){ if (xValue >= alphabet_num.start[i] && xValue <= alphabet_num.end[i]) { console.log(alphabet_num.alphabet[i]); return alphabet_num.alphabet[i]; }else{ return '0'; } } ); // with 350 the array result // result = ['0', '0', 'C', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'] console.log(result); // user findIndex function to find indx let index = result.findIndex(function (value){ return value!='0'; }); // the index of 'C' letter in array result index =2 console.log(index); // get result[2] so I get 'C' letter console.log(result[index]); </script>

about 4 years ago · Juan Pablo Isaza Relatório

0

Puedes usar esto

 alphabet_numBetweenStartAndEnd = function (alphabet_num, xValue) { for (var i = 0; i < alphabet_num.start.length; i++) { if (xValue >= alphabet_num.start[i] && xValue <= alphabet_num.end[i]) { return alphabet_num.alphabet[i]; } } }
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