-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmutation.js
More file actions
29 lines (23 loc) · 965 Bytes
/
Copy pathmutation.js
File metadata and controls
29 lines (23 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
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.
mutation(["hello", "hey"]) // false.
mutation(["hello", "Hello"]) // true.
mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]) // true.
mutation(["Mary", "Army"]) // true.
mutation(["Mary", "Aarmy"]) // true.
mutation(["Alien", "line"]) // true.
mutation(["floor", "for"]) // true.
mutation(["hello", "neo"]) // false.
*/
function mutation(arr) {
// lower casing the arguments
var word = arr[1].toLowerCase();
var target = arr[0].toLowerCase();
for (var i = 0; i < word.length; i++) {
// if any element of first string does not exist in the second string return false else return true
if (target.indexOf(word[i]) === -1) {
return false;
}
}
return true;
}