Hi, here is a neat solution to mutation problem using the every() and includes() methods. After ‘lower casing’ then splitting the strings into individual character elements of arrays…You saw it here first
function mutation(arr) {
let arr0 = arr[0].toLowerCase().split("");
let arr1 = arr[1].toLowerCase().split("");
// For every element in first array is it included in second array?
return arr1.every( (elem) => arr0.includes(elem) );
}
you only need to split the second array to check for every element. the first array doesn’t need to be split because includes function will loop over the entire string in arr[0].
This is a nitpick, so I’m sorry in advance: this pops up fairly often on the forums and it just happens that yours was the one that triggered this response:
This:
const mutation = (arr) => {
Is not “the ES6 version” of
function mutation (arr) {
Saying that changing the second to the first is like saying this: