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

149
Views
Create a function that takes a word and returns true if the word has two consecutive identical letters

// Create a function that takes a word and returns true if the word has two consecutive identical letters.

What am I doing wrong?

module.exports = (word) => {
    for (let i = 0; i <= word.length; i++) {
        for (let j = i + 1; j <= word.length; j++) {
            if (word[j] == word[i]) {
                return true;
            }
        } return false;
        
    } 

};
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can do this with only 1 loop.

function hasConsecutiveIdenticalLetters(word){
    for (let i = 1; i < word.length; i++) {
        if (word[i-1] === word[i]) {
            return true;
        }
    }
    return false;
}
about 4 years ago · Juan Pablo Isaza Report

0

You can also achieve this like below using some

const hasConsecutiveIdenticalLetters = (word: string) => (word).split('').some((letter, index) => letter === word[index + 1]);
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!