Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/ABC-problem/CoffeeScript/abc-problem.coffee
Normal file
18
Task/ABC-problem/CoffeeScript/abc-problem.coffee
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
blockList = [ 'BO', 'XK', 'DQ', 'CP', 'NA', 'GT', 'RE', 'TG', 'QD', 'FS', 'JW', 'HU', 'VI', 'AN', 'OB', 'ER', 'FS', 'LY', 'PC', 'ZM' ]
|
||||
|
||||
canMakeWord = (word="") ->
|
||||
# Create a shallow clone of the master blockList
|
||||
blocks = blockList.slice 0
|
||||
# Check if blocks contains letter
|
||||
checkBlocks = (letter) ->
|
||||
# Loop through every remaining block
|
||||
for block, idx in blocks
|
||||
# If letter is in block, blocks.splice will return an array, which will evaluate as true
|
||||
return blocks.splice idx, 1 if letter.toUpperCase() in block
|
||||
false
|
||||
# Return true if there are no falsy values
|
||||
false not in (checkBlocks letter for letter in word)
|
||||
|
||||
# Expect true, true, false, true, false, true, true, true
|
||||
for word in ["A", "BARK", "BOOK", "TREAT", "COMMON", "squad", "CONFUSE", "STORM"]
|
||||
console.log word + " -> " + canMakeWord(word)
|
||||
Loading…
Add table
Add a link
Reference in a new issue