How to use the find function from underscore

Find comprehensive JavaScript underscore.find code examples handpicked from public code repositorys.

378
379
380
381
382
383
384
385
386
387
var seed = random.float(0, total)

var counter = 0


return _.find(ar, function(a){

    if(counter + a.probability > seed && counter <= seed){
        return true
    }
fork icon33
star icon58
watch icon7

+ 2 other calls in file

80
81
82
83
84
85
86
87
88
89
        'province 3': {
            provinceCard: _.find(provinceThree, (card) => card.isProvince),
            dynastyCards: _.reject(provinceThree, (card) => card.isProvince)
        },
        'province 4': {
            provinceCard: _.find(provinceFour, (card) => card.isProvince),
            dynastyCards: _.reject(provinceFour, (card) => card.isProvince)
        }
    };
}
fork icon18
star icon17
watch icon0

+ 11 other calls in file

294
295
296
297
298
299
300
301
302
  }
}

// Checks if there's an active subscription for the incoming delta
function topicIsSubscribed(topic) {
  return _.find(plugin.subscriptions, subs => {
    return matchTopic(subs.topic, topic);
  }) != undefined;
}
fork icon2
star icon1
watch icon0

9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
};

// Convenience version of a common use case of `find`: getting the first object
// containing specific `key:value` pairs.
_.findWhere = function(obj, attrs) {
  return _.find(obj, _.matcher(attrs));
};

// Return the maximum element (or element-based computation).
_.max = function(obj, iteratee, context) {
fork icon1
star icon1
watch icon2

+ 9 other calls in file

6
7
8
9
10
11
12
13
14
15
16
17
  return admins;
};


exports.find = function(id, done) {
  var _ = require('underscore');
  var returnList = _.find(admins, {adminID: adminID});
  return done(null, returnList);
};


exports.findByAdminID = function(id, done) {
fork icon1
star icon0
watch icon8

37
38
39
40
41
42
43
44
45
46

const xcodeproj = xcode.project(pbxPath);
xcodeproj.parseSync();

const xcBuildConfiguration = xcodeproj.pbxXCBuildConfigurationSection();
const plist_file_entry = _.find(xcBuildConfiguration, entry => entry.buildSettings && entry.buildSettings.INFOPLIST_FILE);
const plist_file = path.join(project_dir, plist_file_entry.buildSettings.INFOPLIST_FILE.replace(/^"(.*)"$/g, '$1').replace(/\\&/g, '&'));
const config_file = path.join(path.dirname(plist_file), 'config.xml');

if (!fs.existsSync(plist_file) || !fs.existsSync(config_file)) {
fork icon0
star icon0
watch icon0

164
165
166
167
168
169
170
171
172
173
174
175
  }
  return isRepeat;
}


function handleCurrDomain(domains, case_env) {
  let currDomain = _.find(domains, (item) => item.name === case_env);


  if (!currDomain) {
    currDomain = domains[0];
  }
fork icon0
star icon0
watch icon1

+ 3 other calls in file

570
571
572
573
574
575
576
577
578
  this._featureViews = {};
}

if (!this._featureViews[featureType]) {
  var featureViews = this.contentFeatureViews.concat(this.deliveryFeatureViews);
  this._featureViews[featureType] = Underscore.find(featureViews, function (featureView) {
    return featureView.model.get('type') === featureType;
  });
}
fork icon0
star icon0
watch icon1

+ 4 other calls in file

60
61
62
63
64
65
66
67
68
69
},
afterFindOne: async function(){
    if (_.isEmpty(this.data.values)) {
        const all = objectql.getAllObjectValidationRules();
        const id = this.id;
        this.data.values = _.find(all, function (item) {
            return item._id === id
        });
    }
},
fork icon0
star icon0
watch icon1

63
64
65
66
67
68
69
70
71
72
    }
},
afterFindOne: async function(){
    let id = this.id;
    if(id && _.isEmpty(this.data.values) && this.spaceId === 'template'){
        this.data.values = _.find(getFlows(), function(flow){
            return flow._id === id;
        })
    }
},
fork icon0
star icon0
watch icon1

82
83
84
85
86
87
88
89
90
91
    return result.map(function(values) {
        return values.withValue(exports.sequence.source, source);
    });
};
rule.head = function() {
    var firstCapture = _.find(parsers, isCapturedRule);
    return exports.then(
        rule,
        exports.sequence.extract(firstCapture)
    );
fork icon0
star icon0
watch icon1

164
165
166
167
168
169
170
171
172
173
174
175
  }
  return isRepeat;
}


function handleCurrDomain(domains, case_env) {
  let currDomain = _.find(domains, item => item.name === case_env);


  if (!currDomain) {
    currDomain = domains[0];
  }
fork icon0
star icon0
watch icon1