Nodejs Array Select selectMany(selector, resSelector)

Here you can find the source of selectMany(selector, resSelector)

Method Source Code

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) }));
   }, []);// w  ww  .j  ava 2s  . co m
};

Related

  1. select(selectFunction)
    Array.prototype.select = function(selectFunction) {
        return this.inject([], function(result, element) {
            if (selectFunction(element)) {
                result.push(element);    
            return result;
        });
    };
    
  2. select(selector)
    Array.prototype.select = function (selector) {
        if (selector == null || typeof (selector) !== 'function') throw new Error('selector should');
        var result = [];
        for (var i = 0; i < this.length; i++) {
            result.push(selector(this[i]));
        return result;
    };
    
  3. select(selector, context)
    Array.prototype.select = Array.prototype.map || function (selector, context) {
      context = context || window;
      var arr = [];
      var l = this.length;
      for (var i = 0; i < l; i++)
        arr.push(selector.call(context, this[i], i, this));
      return arr;
    };
    
  4. select(transformer)
    Array.prototype.select = function(transformer) {
        if (typeof(transformer) != "function") {
            throw new Error("The argument must be a function");
        var arr = [];
        for (var i = this.length - 1; i >= 0; i--) {
            arr[i] = transformer(this[i]);
        return arr;
    ...
    
  5. 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 = [];
    ...
    
  6. 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
    
  7. selectOne(filter)
    Array.prototype.selectOne = function(filter)
      for (var i = 0; i< this.length; i++) {
        if(filter(this[i])){
          return this[i];
      return null;
    
  8. 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 = "";
    ...
    
  9. selects(cond)
    Array.prototype.selects = function (cond) {
      var results = [];
      this.forEach(function (el) {
        if (cond(el)) {
          results.push(el);
      });
      return results