Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active December 15, 2022 08:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save McLarenCollege/6de56bd267f8084c12904673a87b4ed7 to your computer and use it in GitHub Desktop.
Save McLarenCollege/6de56bd267f8084c12904673a87b4ed7 to your computer and use it in GitHub Desktop.

Find Word

Write a function findWord which takes a matrix of characters and a target word, and returns true if the word appears vertically at some position in the matrix

Note:

  • Every element in the matrix will be a string of length 1
  • You should only consider the top-down direction (ie. not left-right or down-up, etc)

Example 1

let easyPuzzle = [
    ['b', 'a', 't'],
    ['i', 'i', 'p'],
    ['t', 'o', 'n']
];
console.log(findWord(easyPuzzle, 'bit')); // should print true
console.log(findWord(easyPuzzle, 'bat')); // should print false

Example 2

let hardPuzzle = [
    ['y', 'o', 't', 'v'],
    ['k', 'c', 'p', 's'],
    ['t', 'h', 'n', 's'],
    ['t', 'a', 'o', 'e'],
    ['t', 't', 'a', 'i'],
];
console.log(findWord(hardPuzzle, 'chat')); // should print true
console.log(findWord(hardPuzzle, 'set')); // should print false
console.log(findWord(hardPuzzle, 'i')); // should print true

CODE TEMPLATE


function findWord(puzzle,word){
// write your code here
}
let easyPuzzle = [
    ['b', 'a', 't'],
    ['i', 'i', 'p'],
    ['t', 'o', 'n']
];
console.log(findWord(easyPuzzle, 'bit')); // should print true
console.log(findWord(easyPuzzle, 'bat')); // should print false
let hardPuzzle = [
    ['y', 'o', 't', 'v'],
    ['k', 'c', 'p', 's'],
    ['t', 'h', 'n', 's'],
    ['t', 'a', 'o', 'e'],
    ['t', 't', 'a', 'i'],
];
console.log(findWord(hardPuzzle, 'chat')); // should print true
console.log(findWord(hardPuzzle, 'set')); // should print false
console.log(findWord(hardPuzzle, 'i')); // should print true

Please watch this video for a hint for the problem.

@WajiiCode07
Copy link

hi

@ifeoluwaoladosu
Copy link

day0.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment