Nodejs Array Select selects(cond)

Here you can find the source of selects(cond)

Method Source Code

Array.prototype.selects = function (cond) {
  var results = [];
  this.forEach(function (el) {
    if (cond(el)) {
      results.push(el);/*  ww  w  . ja  v a  2 s.com*/
    }
  });
  return results
}

Related

  1. selectMany(fn)
    let src = [
        [1, 2, 3, 4],
        [2, 7, 8, 9],
        [1, 2, 3, 4],
    ];
    let src1 = [1, 123, 567];
    Array.prototype.selectMany = function(fn) {
        let resultArray = [];
        let result = [];
    ...
    
  2. selectMany(selector, resSelector)
    Array.prototype.selectMany = function (selector, resSelector) {
      resSelector = resSelector || function (i, res) { return res; };
      return this.aggregate(function (a, b) {
        return a.concat(selector(b).select(function (res) { return resSelector(b, res) }));
      }, []);
    };
    
  3. selectObjects(key, array)
    Array.prototype.selectObjects = function(key, array){
      var toReturn = []
      $.each(this, function(i, object){
        if(array.indexOf(object[key]) > -1){
          toReturn.push(object)
      })
      return toReturn
    
  4. selectOne(filter)
    Array.prototype.selectOne = function(filter)
      for (var i = 0; i< this.length; i++) {
        if(filter(this[i])){
          return this[i];
      return null;
    
  5. selectRandom()
    var alphabet = "aabcdeefghiijklmnoopqrstuuvwxyyz";
    function randint(min, max) {
        return Math.floor(Math.random() * (max - min)) + min;
    Array.prototype.selectRandom = function() {
        return this[randint(0, this.length)];
    };
    function random_word(min, max) {
        var word = "";
    ...