Skip to content

Commit fc636b1

Browse files
committed
add mutation example
1 parent 4bc229e commit fc636b1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,33 @@ function getIndexToIns(arr, num) {
486486

487487
getIndexToIns([10, 20, 30, 40, 50], 35);
488488
```
489+
490+
### 15. Mutations
491+
492+
_Difficulty: Beginner_
493+
494+
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.
495+
496+
For example, ["hello", "Hello"], should return `true` because all of the letters in the second string are present in the first, ignoring case.
497+
498+
The arguments `["hello", "hey"]` should return `false` because the string `hello` does not contain a `y`.
499+
500+
Lastly, `["Alien", "line"]`, should return `true` because all of the letters in `line` are present in `Alien`.
501+
502+
---
503+
504+
#### Solution
505+
506+
```js
507+
function mutation(arr) {
508+
const arr1 = arr[0].toLowerCase().split("");
509+
const arr2 = arr[1].toLowerCase().split("");
510+
for (let i = 0; i < arr2.length; i++) {
511+
if (arr1.indexOf(arr2[i]) == -1) {
512+
return false;
513+
}
514+
}
515+
return true;
516+
}
517+
mutation(["hello", "hey"]);
518+
```

0 commit comments

Comments
 (0)