Untitled
unknown
plain_text
2 years ago
870 B
5
Indexable
let puzzles = [ ['a', 'k', 'f', 'o', 'x', 'e', 's'], ['s', 'o', 'a', 'w', 'a', 'h', 'p'], ['i', 't', 'c', 'k', 'e', 't', 'n'], ['o', 't', 's', 'd', 'h', 'o', 'h'], ['s', 'e', 'x', 'g', 's', 't', 'a'], ['u', 'r', 'p', 'i', 'w', 'e', 'u'], ['z', 's', 'b', 'n', 'u', 'i', 'r'], ]; function searchStraightLineInclude(word, puzzle) { const arrayCopy = JSON.parse(JSON.stringify(puzzle)); console.log(arrayCopy); let verticalStr = []; for (let i = 0; i < puzzle.length; i += 1) { for (let j = 0; j < puzzle[i].length; j += 1) { verticalStr.push(arrayCopy[j][i]); } if (verticalStr.join('').includes(`${word}`)) return true; if (arrayCopy[i].join('').includes(`${word}`)) return true; if (arrayCopy[i].reverse().join('').includes(`${word}`)) return true; verticalStr = []; } } searchStraightLineInclude('otters', puzzles)
Editor is loading...