bracket.js
// The second parameter is the index to search
The second parameter is the index to search
The second parameter is the index to search
function has(param1, param2) {
    var 
      len = arguments.length,
      compare = len == 1 ? param1 : param2,
      callback,
      obj = {};
    if(_.isArr(compare)) {
      var len = compare.length;
      callback = function(key) {
        for(var ix = 0; ix < len; ix++) {
          if (indexOf(key, compare[ix]) > -1) {
            return true;
          }
        }
        return false;
      }
    } else {
      callback = function(key) {
        return indexOf(key, compare) > -1;
      }
    }
    if(len == 2) {
      obj = {};
      obj[param1] = callback;
      return obj;
    } else {
      return callback;
    }
  }
function has ( param1 , param2 ) { var len = arguments . length , compare = len == 1 ? param1 : param2 , callback , obj = { } ; if ( _ . isArr ( compare ) ) { var len = compare . length ; callback = function ( key ) { for ( var ix = 0 ; ix < len ; ix ++ ) { if ( indexOf ( key , compare [ ix ] ) > - 1 ) { return true ; } } return false ; } } else { callback = function ( key ) { return indexOf ( key , compare ) > - 1 ; } } if ( len == 2 ) { obj = { } ; obj [ param1 ] = callback ; return obj ; } else { return callback ; } }
The second parameter is the index to search
The second parameter is the index to search
// This becomes O(N * M) // This is O(N)