title: How to write a function that returns true if a portion of str1 can be rearranged to str2?
body: <p>I am having trouble with below question. I basically have to write a code/function that returns true if a portion of str1 can be rearraged to str2.</p>
  
  <p>Write function scramble(str1,str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false.</p>
  
  <p>For example:
  str1 is 'rkqodlw' and str2 is 'world' the output should return true.
  str1 is 'cedewaraaossoqqyt' and str2 is 'codewars' should return true.
  str1 is 'katas' and str2 is 'steak' should return false.</p>
  
  <p>Only lower case letters will be used (a-z). No punctuation or digits will be included.
  Performance needs to be considered.</p>
  
  <p>Below is the current code I have:</p>
  
  <pre><code>function scramble(str1, str2) {
    var first; //longer string
    var second; //shorter string
  
    if(str1 || str2 === "undefined") {
      return false;
    }
  
    if(str1.length &gt; str2.length) {
      first = str1;
      second = str2
    } else if(str2.length &gt; str1.length) {
      first = str2;
      second = str1;
    }
  
    for (i=0; i&lt;second.length; i++) {
      if (first.indexOf(second[i]) === -1) {
        return false;
      }
    }
  
    return true;
  
  }
  </code></pre>
  
  <p>Could you please help me with this question?</p>