Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
Verifique si la cadena dada contiene 3 palabras seguidas. Usando javascript

Aquí está mi intento, pero no funciona. Lo estoy codificando en el sitio web de checkIo. Funciona bien en mi editor local, pero falló en checkIO dando el error 'su resultado indefinido' para la prueba 'hola mundo hola' la cadena pasada puede contener un número, palabra mezclada con número, sólo la palabra sin número debe contarse en sucesión.

 function wordChecker(text){ let arr=text.split(' '); let counter=0; for(let i=0;i<arr.length;i++){ if(isNaN(arr[i])){ counter++; if(counter===3){ return true } } else { counter=0; } } return false; } wordChecker('hello world Hello'); wordChecker('hey I don't43 qualify'); '''
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La forma sencilla de hacerlo es hacer un bucle de las palabras, siguiendo la pista de la palabra anterior, incrementando un contador cuando la palabra actual coincide con la anterior...

 function hasNConseqWords(text, n=3) { const words = text.split(' '); let lastWord = null; let successiveCount; for (let word of words) { if (word === lastWord) { successiveCount++; if (successiveCount === n) return { n, word }; } else { successiveCount = 1; lastWord = word; } } return { n, word: null }; } console.log(hasNConseqWords('now is the the the time for all good men')) console.log(hasNConseqWords('now is the the time for all good men to come to'))

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!