I am given a string and an array of single character strings as an argument. I need to return the shortest substring that can be found in the given string that contains every character in the array.
I am assuming that all characters are lower case and that the substring will be at least two characters long.
This is how I have it set up:
const solve = (strArg, charArray) => {
let result = '';
const strArray = strArg.split('');
return;
}
solve("environmental earth science", ["n","e","i","m"]);
I want to loop over the strArg
and say does this letter exist in the charArray
, but I want to use an ES6 array helper method and I have looked at filter()
, but if I look at how T.J Crowder defines the use of filter()
, that is more for creating a new array.
So then I have also looked at the for..of
loop, but I am unclear as to whether I am applying it wrong or the for..of
is not the best for the job. I need to iterate over each character in strArray
and see if it exists in charArray
.