Nodejs Array Select select(selector)

Here you can find the source of select(selector)

Method Source Code

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]));/*w w w .j a  v a  2s .  c  o m*/
    }
    return result;
};

Related

  1. select(func)
    Array.prototype.select = function (func) {
        var length = this.length,
            items = [];
        for (var i = 0; i < length; i++) {
            items.push(func(this[i]));
        return items;
    
  2. select(lambda)
    Array.prototype.select = function(lambda) {
        if (lambda == undefined) {
            return this;
        } else {
            result = [];
            for (i = 0; i < this.length; i++) {
                if (lambda(this[i])) {
                    result.push(this[i]);
            return result;
    };
    
  3. select(predicate)
    Array.prototype.select = function(predicate){
        var r = []
        for(var n = 0; n < this.length; n++) {
            if(predicate(this[n])){
                r.push(this[n]);
        return r;
    };
    ...
    
  4. select(projection)
    Array.prototype.select = function (projection) {
        var results = [];
        for (var i = 0; i < this.length; i++) {
            results.push(projection(this[i]));
        return results;
    };
    var children = [{ id: 1, Name: "Rob" }, { id: 2, Name: "Sansa" }, { id: 3, Name: "Arya" }, { id: 4, Name: "Brandon" }, { id: 5, Name: "Rickon" }];
    var filteredChildren = children.where(function (x) {
    ...
    
  5. select(selectFunction)
    Array.prototype.select = function(selectFunction) {
        return this.inject([], function(result, element) {
            if (selectFunction(element)) {
                result.push(element);    
            return result;
        });
    };
    
  6. 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;
    };
    
  7. 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;
    ...
    
  8. 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 = [];
    ...
    
  9. 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) }));
      }, []);
    };