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

224
Visualizações
I am trying to use a if statement to determine if the roman numerals is 4, 9, 40, 90, 400, 900 but I am getting undefined

I am getting undefined when I try to run my code, I am not sure why it is not triggering the first condition, does anyone know what I am doing wrong. At this point I know there is a better solution to solve this problem, but I would like to know what I am doing wrong in this particular instance.

var romanToInt = function(s) {
  let romanNumerals = {I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000}
  let integer = 0
  let sToIndex = s.split("")
  
  for (let i = 0; i <= sToIndex.length; i++ ){
      for (let j = 0; j <= romanNumerals.length -1; j++){
          if (sToIndex[i] === "I" && (sToIndex[i + 1] === "V" || "X")){
             integer = Object.values(romanNumerals)[j + 1] - 1
             console.log(integer) 
           }
            else if (Object.key(sToIndex)[i] === "X" & Object.key(sToIndex)[i + 1] === "C"|| "L"){
                integer = Object.values(romanNumerals)[j + 1] - 10
                return integer 
            }else if (Object.key(sToIndex)[i] === "C" & Object.key(sToIndex)[i + 1] === "D" || "M"){
              integer = Object.values(romanNumerals)[j + 1] - 10
              return integer
            }else {
              integer = Object.values(romanNumerals)[j] + Object.values(romanNumerals)[j+1]
              return integer 
            }
          }
        }

}

console.log(romanToInt("IV"))
about 4 years ago · Juan Pablo Isaza
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