Returning a result of true if all the individual characters of pattern appear in string
<p>I'm writing a piece of JS code that returns a result of true if if pattern appears in string as a substring (case sensitive) but would like to extend its functionality to returns true if all the individual characters of pattern appear in string (regardless of order). </p>

<p>For example:</p>

<p>This is what the program currently does:</p>

<pre><code>match1("adipisci","pis") returns true
</code></pre>

<p>Whereas I would now like it to do this:</p>

<pre><code>match1("adipisci","sciip") returns true
match2("adipisci","sciipx") returns false because x does not exist in variable
</code></pre>

<p>I am having difficulty implementing this into my code:</p>

<pre><code>var pages=[
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
  "Nulla imperdiet laoreet neque.",
  "Praesent at gravida nisl. Quisque tincidunt, est ac porta malesuada, augue lorem posuere lacus, vitae commodo purus nunc et lacus."
  ];
var search_term = prompt('Type in search term: ','Search word');
// ask which search term the user wants to search for with default being 'Search Term' 
function find_s(w) {
    var indexes = [0,0,0] // create an array  to hold pages where search term found
    var iii = 0 // create variable to increment the number of finds in each page
    for (var ii=0;ii&lt;pages.length;ii++) {
    // for each page in the array
        for (var i=0;i&lt;pages[ii].length;i++) {
        // for each character in the chosen page
            if (pages[ii].substr(i,w.length).toLowerCase()==w.substr(0,w.length).toLowerCase()) {
            // check to see if the search term is there ignoring case
                iii++;
                // increment number of times the search term in found
                while(pages[ii].substr(i,1)!=" ") {
                    // move to the next word but checking for spaces
                    i++;
                    }
            }
        }
        indexes[ii]=iii;
        // update the number of times the search term is found in that page
        iii=0;
        // reset counter for next page search
    }
    return (w + " was found in this may times in each page " + indexes);
    // let the user know the result
}
alert (find_s(search_term));
</code></pre>

<p>I would appreciate any guidance into the right direction - thanking you in advance!</p>
