Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
32
Task/ABC-Problem/JavaScript/abc-problem.js
Normal file
32
Task/ABC-Problem/JavaScript/abc-problem.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
let characters = "BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM";
|
||||
let blocks = characters.split(" ").map(pair => pair.split(""));
|
||||
|
||||
function isWordPossible(word) {
|
||||
var letters = [...word.toUpperCase()];
|
||||
var length = letters.length;
|
||||
var copy = new Set(blocks);
|
||||
|
||||
for (let letter of letters) {
|
||||
for (let block of copy) {
|
||||
let index = block.indexOf(letter);
|
||||
|
||||
if (index !== -1) {
|
||||
length--;
|
||||
copy.delete(block);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return !length;
|
||||
}
|
||||
|
||||
[
|
||||
"A",
|
||||
"BARK",
|
||||
"BOOK",
|
||||
"TREAT",
|
||||
"COMMON",
|
||||
"SQUAD",
|
||||
"CONFUSE"
|
||||
].forEach(word => console.log(`${word}: ${isWordPossible(word)}`));
|
||||
Loading…
Add table
Add a link
Reference in a new issue