Nodejs Array Reorder reorder(a)

Here you can find the source of reorder(a)

Method Source Code

var myArray = ['one', 'two', 'three','four', 'five'];

Array.prototype.reorder = function (a){
  var o = [], _ = this, i = 0;
  _.forEach(function(){
    o.push(_[a[i]] ? _[a[i]] : _[i]);/*from w ww.  java  2  s. c om*/
   i++;
  });
  return o;
};
console.log( myArray.reorder([1, 0, 2, 2, 4, 5]) );

Related

  1. reorder(a)
    Array.prototype.reorder = function (a){
      var o = [], _ = this, i = 0;
      _.forEach(function(){
        o.push(_[a[i]] ? _[a[i]] : _[i]);
      i++;
      });
      return o;
      };
    
  2. reorder(mapping)
    Array.prototype.reorder = function (mapping) {
      return mapping.map(index => this[index])