Question: Suppose we have 2 arrays:

```
var a1=[pencil,pencils,boxes,max]

var a2=[pencils,box]

```

and I need just "max" as my resultant array, i.e.:

```
var result = [max]

```

That means I want to subtract(i.e, difference of sets) all the possibilities(means. plural form) of every word(i.e, elements) in array that means I want to eliminate box(es) (a1 element) which is the (plural form) of word "box"(element of a2).

So in order to have my desired result (i.e, "max") I need to eleminate all the elements (include its plural form) IE: box(es) (and same goes for pencil(s)) 

So my question is how can I create a loop(or a function) which match and remove every elements(incl. its plural form) of the array i.e, box(es) or pencil(s)
so that I can have "max" as my resultant array!

I hope this clarifies my question(how to filter an array using another array and regexp)!

Answer: 
You can utilize `Array.prototype.filter` to do this:

```
var a1=['pencil', 'pencils', 'boxes', 'max'];
var a2=['pencils', 'box'];

var result = a1.filter(function(item) {
    if (isPluralForm(item))
        return a2.indexOf(item) === -1 && a2.indexOf(singleFormOf(item)) === -1;
    else
        return a2.indexOf(item) === -1 && a2.indexOf(pluralFormOf(item)) === -1;
});

```

As simple as that. We just want to get items of `a2` which are not present in `a1` in either single or plural form.

What about `isPlural`, `pluralFormOf` and `singleFormOf`? It is up to you. You need to implement it yourself or find a third-party solution.

For example, that's how you can implement `pluralFormOf`:

```
var irregularPluralForms = {
    'sheep': 'sheep', // same form
    'foot': 'feet' // irregular form
};

function pluralFormOf(word)
{
    if (irregularPluralForms[word] !== undefined)
        return irregularPluralForms[word];

    if (word.substr(word.length - 1) === 'y')
        return word.substr(0, word.length - 1) + 'ies';

    if (word.substr(word.length - 1) === 's'
     || word.substr(word.length - 1) === 'x'
     || word.substr(word.length - 1) === 'z'
     || word.substr(word.length - 2) === 'ch'
     || word.substr(word.length - 2) === 'sh')
        return word + 'es';

    return word + 's';
}

```

I have used [the following article](http://www.edufind.com/english-grammar/plural-nouns/) to build this function.
```
var a1=[pencil,pencils,boxes,max];
var a2=[pencils,box];

var result = _.filter(a1, function(obj){ return !_.findWhere(a2, obj); });

```

> 
> result = [max] with Underscore JS library.
> 
> 
>