Verifying if a string can be created with the letters of another string This is basically based on the following question on stackoverflow which was based on a codewars assignment that can be found here
Problem statement

Complete the function scramble(str1, str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false.

Notes:


Only lower case letters will be used (a-z). No punctuation or digits will be included.
Performance needs to be considered


My solution
function scramble(str1, str2) {
  if (str1.length &lt; str2.length) {
    return false;
  }
  const set = new Set([...str2]);
  return Array.from( set ).every( letter =&gt; str2.split(letter).length &lt;= str1.split(letter).length );
}

As with the original question on SO, my question would be if there are more efficient ways of completing the assignment. I am mainly worried about the string.split, but I didn't know of any other method that might be faster (I know I should substract 1 to get the actual letter count, but it doesn't matter for this usecase)
Your logic seems hard to follow.  Why spread str2 to array, which you then read into a Set, only to turn around and make the Set into an array, which you then iterate, comparing each letter’s count in each string by splitting them repeatedly?
You see how long and convoluted that sentence was? The last line of code there is kind of the same, dense and hard to follow.
The problem should be solved by counting characters for str1 into map keyed by each letter. You then iterate through str2 and decrement those counters. If any counter goes to -1 you have false condition.  This approach means each letter in passed string only needs to be visited once making performance linear to the combined length of the strings in operational complexity.  Your current solution has exponential complexity.