Guest User

Untitled

a guest
Oct 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. ** You should simply use indexOf or some ... that's are JS 1.6 Array methods **
  2.  
  3. Array.prototype.has = function(obj) {
  4. return this.indexOf(obj) !== -1;
  5. };
  6.  
  7. Array.prototype.has = function(obj) {
  8. return this.some(function(e){return e === obj});
  9. };
  10.  
  11. ** This implementation is for multiple search (more than one value that should be present) **
  12.  
  13. Array.prototype.has = function() {
  14. var i = arguments.length,
  15. result = [];
  16. while(i)
  17. result.push(this.indexOf(arguments[--i]) !== -1);
  18. return result.every(function(e){return e});
  19. };
  20.  
  21. alert([1,2,3].has(3)); //true
  22. alert([1,2,3].has(2,4)); // false
  23. alert([1,2,3].has(1,2,3)); // true
Add Comment
Please, Sign In to add comment