Leetcode word ladder

im getting 1 when im suppose to get 0



/**
 * @param {string} beginWord
 * @param {string} endWord
 * @param {string[]} wordList
 * @return {number}
 */
var ladderLength = function(beginWord, endWord, wordList) {
    if(wordList.includes(endWord) && wordList.includes(beginWord) == false  && endWord.length == beginWord.length && 1 <= wordList.length <= 5000 && beginWord != endWord ){
        for(let i = 0; i < wordList.length; i++){
           const lower = wordList[i].toLowerCase();
            if(endWord === lower && wordList[i].length == beginWord.length){
              return  wordList.indexOf(lower);
            }
        }
    }else{
        return 0;
    }
};
console.log(ladderLength(''hot,'dpg',['hot','dog'])

What debugging have you tried so far?

wordList.includes(beginWord) === false 

but then this one doesnt pass
beginWord =

“hot”

endWord =

“dog”

wordList =

[“hot”,“dog”]

Output

1

Expected

0

I’m not sure where that change would go. Can you say more?


/
var ladderLength = function(beginWord, endWord, wordList) {
    if(wordList.includes(endWord) && wordList.includes(beginWord) === false  &&wordList.includes(beginWord) == false  && endWord.length == beginWord.length && 1 <= wordList.length <= 5000 && beginWord != endWord ){
        for(let i = 0; i < wordList.length; i++){
           const lower = wordList[i].toLowerCase();
            if(endWord === lower && wordList[i].length == beginWord.length){
              return  wordList.indexOf(lower);
            }
        }
    }else{
        return 0;
    }
};
console.log(ladderLength(''hot,'dpg',['hot','dog'])

The code helps but can you also use words to talk about why you think that change could have helped?

I put the constraints into the if statement là and it said thst beginword didn’t need to be in the array so wordlist inckyde begin word to == false which would pass the hot dog test case but wouldn’t pas the b = a e = c [a,b,c] with 0 but suppose to be 2 test case but when I remove the include for beginword abc test case would psss

hmm, those are really complicated if statement conditions, which is a big red flag. Can you make them simpler?

sorry i tried going simpler but other test cases stop passing