Write a function called closeMatch
which takes two strings and returns true if they
have the same length and differ by only one character.
CODE TEMPLATE
function closeMatch(str1, str2){
// write your code here
}
console.log(closeMatch('bard', 'barn')); // should return true
console.log(closeMatch('broad', 'road')); // should return false
console.log(closeMatch('rated', 'barn')); // should return false
console.log(closeMatch('strength', 'steength')); // should return true
console.log(closeMatch('yesterday', 'yesterday')); // should return false
Write a function called spellCheck
which takes two parameters:
- A test word which may or may not be spelled correctly
- A list of dictionary words
The function should return the list of dictionary words where the test word is a close match as defined in Part 1.
If the word is present in the dictionary it should return an empty array.
CODE TEMPLATE
function spellCheck(word, dictionary){
// write your code here
}
let smallDictionary = [
"jail",
"sail",
"cat",
"table",
"safe",
"call",
"sane",
];
console.log(spellCheck('cail', smallDictionary)); // should return ['jail', 'sail', 'call']
console.log(spellCheck('sane', smallDictionary)); // should return [] because it's correctly spelled
console.log(spellCheck('sate', smallDictionary)); // should return ['safe', 'sane']
Please watch this video for a hint for the problem: