3.1 KiB
3.1 KiB
id, title, isRequired, challengeType, forumTopicId, localeTitle
id | title | isRequired | challengeType | forumTopicId | localeTitle |
---|---|---|---|---|---|
af2170cad53daa0770fabdea | Mutations | true | 5 | 16025 | Мутации |
Description
["hello", "Hello"]
должен возвращать true, потому что все буквы во второй строке присутствуют в первом, игнорирующем случае. Аргументы ["hello", "hey"]
должны возвращать false, потому что строка "hello" не содержит "y". Наконец, ["Alien", "line"]
должен возвращать true, потому что все буквы в «строке» присутствуют в «Alien». Не забудьте использовать Read-Search-Ask, если вы застряли. Напишите свой собственный код.
Instructions
Tests
tests:
- text: <code>mutation(["hello", "hey"])</code> should return false.
testString: assert(mutation(["hello", "hey"]) === false);
- text: <code>mutation(["hello", "Hello"])</code> should return true.
testString: assert(mutation(["hello", "Hello"]) === true);
- text: <code>mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])</code> should return true.
testString: assert(mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]) === true);
- text: <code>mutation(["Mary", "Army"])</code> should return true.
testString: assert(mutation(["Mary", "Army"]) === true);
- text: <code>mutation(["Mary", "Aarmy"])</code> should return true.
testString: assert(mutation(["Mary", "Aarmy"]) === true);
- text: <code>mutation(["Alien", "line"])</code> should return true.
testString: assert(mutation(["Alien", "line"]) === true);
- text: <code>mutation(["floor", "for"])</code> should return true.
testString: assert(mutation(["floor", "for"]) === true);
- text: <code>mutation(["hello", "neo"])</code> should return false.
testString: assert(mutation(["hello", "neo"]) === false);
- text: <code>mutation(["voodoo", "no"])</code> should return false.
testString: assert(mutation(["voodoo", "no"]) === false);
Challenge Seed
function mutation(arr) {
return arr;
}
mutation(["hello", "hey"]);
Solution
function mutation(arr) {
let hash = Object.create(null);
arr[0].toLowerCase().split('').forEach(c => hash[c] = true);
return !arr[1].toLowerCase().split('').filter(c => !hash[c]).length;
}
mutation(["hello", "hey"]);