forked from lighthouse-labs/pair-programming-word-search
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordsearch.js
More file actions
34 lines (28 loc) · 753 Bytes
/
wordsearch.js
File metadata and controls
34 lines (28 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//paired programming LHL May 25 Cohrt Rob W and Rubin J
const wordSearch = (letters, word) => {
if (letters.length === 0) {
return undefined;
}
for (let i = 0; i < letters[0].length; i++) {
let result = '';
for (const arr of letters) {
if (typeof arr[i] !== 'string') {
return undefined;
}
result += arr[i];
if (result.includes(word)) {
return true;
}
}
}
const horizontalJoin = letters.map(ls => ls.join(''))
console.log("wordSearch -> horizontalJoin", horizontalJoin)
//
for (l of horizontalJoin) {
if (l.includes(word)) {
return true;
}
} return false;
j
};
module.exports = wordSearch