Folks I have a jquery function requirement that will compare two arrays.
listA = [' APPLE', 'banana', 'orange'] listB = [ 'BANANA ','appl']
ok so in above example, I need function to return "true". Basically what I need is a way to
- Strip each word in both arrays to get rid of leading and trailing spaces.
- Perform comparison which needs to be case insensitive.
- Compare substring level, which means 'appl' does exist within ' APPLE', so it should be true
my code so far
<script> $(document).ready(function(){ Array.prototype.contains = function(array) { return array.every(function(item) { array = $.map(this, function(value){ return value.replace(/ /g, '').toUpperCase(); }); return array.indexOf(item.replace(/ /g, '').toUpperCase()) >= 0; }, this); } var result = [' APPLE', 'banana ', 'orange'].contains([ ' BANANA',' Appl ']); alert(result); }); so in above code example, it should return "true"
Any help is much appreciated