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

Tell us what’s happening: How can i group the letters in the second parameter without caring for the order they are in ? My code is half complete. Ik there are other ways to do this challenge but is it possible to use regex ? help is appretiated

Your code so far

function mutation(arr) {
let one = arr[0];
let two= arr[1];
let testRegex = new RegExp((two), "ig");
let result = testRegex.test(one);
return result

mutation(["hello", "hey"]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

Challenge: Mutations

Link to the challenge:

I’d say doing it with regex isn’t impossible, but absolutely unsuited for this particular challenge. Currently, you check if the characters in two can be found in one in that order.

mutation(["hello","hell"]) would correctly return true with your approach. mutation(["hello","lleh"]) would (incorrectly) return false.

You’d have to check individual characters, so it would make more sense to split('') both strings and then use array methods like includes() or indexOf() to compare the letters.


it is totally possible to use regex, it’s not easy, it’s pretty hard

it’s easier in other ways

it needs to return true if all letters in second string are present in first string

right now your regex is /hey/ig which will give true only if the letters are present in order