You are given a collection of ABC blocks (e.g., childhood alphabet blocks). There are 20 blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks:
(B O)
(X K)
(D Q)
(C P)
(N A)
(G T)
(R E)
(T G)
(Q D)
(F S)
(J W)
(H U)
(V I)
(A N)
(O B)
(E R)
(F S)
(L Y)
(P C)
(Z M)
Some rules to keep in mind:
Once a letter on a block is used, that block cannot be used again. The function should be case-insensitive.Implement a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks.
canMakeWord is a function.
testString: 'assert(typeof canMakeWord === ''function'', ''canMakeWord is a function.'');'
- text: canMakeWord should return a boolean.
testString: 'assert(typeof canMakeWord(''hi'') === ''boolean'', ''canMakeWord should return a boolean.'');'
- text: canMakeWord("bark") should return true.
testString: 'assert(canMakeWord(words[0]), ''canMakeWord("bark") should return true.'');'
- text: canMakeWord("BooK") should return false.
testString: 'assert(!canMakeWord(words[1]), ''canMakeWord("BooK") should return false.'');'
- text: canMakeWord("TReAT") should return true.
testString: 'assert(canMakeWord(words[2]), ''canMakeWord("TReAT") should return true.'');'
- text: canMakeWord("COMMON") should return false.
testString: 'assert(!canMakeWord(words[3]), ''canMakeWord("COMMON") should return false.'');'
- text: canMakeWord("squAD") should return true.
testString: 'assert(canMakeWord(words[4]), ''canMakeWord("squAD") should return true.'');'
- text: canMakeWord("conFUSE") should return true.
testString: 'assert(canMakeWord(words[5]), ''canMakeWord("conFUSE") should return true.'');'
```