2018-10-04 14:37:37 +01:00
|
|
|
---
|
|
|
|
id: af2170cad53daa0770fabdea
|
|
|
|
title: Mutations
|
|
|
|
challengeType: 5
|
2019-07-31 11:32:23 -07:00
|
|
|
forumTopicId: 16025
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: mutations
|
2018-10-04 14:37:37 +01:00
|
|
|
---
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --description--
|
|
|
|
|
2018-10-04 14:37:37 +01:00
|
|
|
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
For example, `["hello", "Hello"]`, should return true because all of the letters in the second string are present in the first, ignoring case.
|
|
|
|
|
|
|
|
The arguments `["hello", "hey"]` should return false because the string "hello" does not contain a "y".
|
|
|
|
|
|
|
|
Lastly, `["Alien", "line"]`, should return true because all of the letters in "line" are present in "Alien".
|
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
|
|
|
`mutation(["hello", "hey"])` should return false.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['hello', 'hey']) === false);
|
2018-10-04 14:37:37 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`mutation(["hello", "Hello"])` should return true.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(mutation(['hello', 'Hello']) === true);
|
|
|
|
```
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])` should return true.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
|
|
|
```js
|
2020-11-27 19:02:05 +01:00
|
|
|
assert(mutation(['zyxwvutsrqponmlkjihgfedcba', 'qrstu']) === true);
|
|
|
|
```
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`mutation(["Mary", "Army"])` should return true.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['Mary', 'Army']) === true);
|
2018-10-04 14:37:37 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`mutation(["Mary", "Aarmy"])` should return true.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['Mary', 'Aarmy']) === true);
|
|
|
|
```
|
|
|
|
|
|
|
|
`mutation(["Alien", "line"])` should return true.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['Alien', 'line']) === true);
|
|
|
|
```
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`mutation(["floor", "for"])` should return true.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(mutation(['floor', 'for']) === true);
|
|
|
|
```
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`mutation(["hello", "neo"])` should return false.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(mutation(['hello', 'neo']) === false);
|
|
|
|
```
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`mutation(["voodoo", "no"])` should return false.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['voodoo', 'no']) === false);
|
|
|
|
```
|
|
|
|
|
|
|
|
`mutation(["ate", "date"]` should return false.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['ate', 'date']) === false);
|
|
|
|
```
|
|
|
|
|
|
|
|
`mutation(["Tiger", "Zebra"])` should return false.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['Tiger', 'Zebra']) === false);
|
|
|
|
```
|
|
|
|
|
|
|
|
`mutation(["Noel", "Ole"])` should return true.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(mutation(['Noel', 'Ole']) === true);
|
|
|
|
```
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
|
|
|
function mutation(arr) {
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutation(["hello", "hey"]);
|
|
|
|
```
|
|
|
|
|
|
|
|
# --solutions--
|
2018-10-04 14:37:37 +01:00
|
|
|
|
|
|
|
```js
|
|
|
|
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"]);
|
|
|
|
```
|