jsshort
Version:
It will make your codes much short and easiar
60 lines (59 loc) • 1.71 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.fndInd = exports.rdcR = exports.rdc = exports.forE = exports.inArray = exports.lstInd = exports.ind = exports.add = void 0;
// Define the methods
function add() {
return this.concat();
}
exports.add = add;
function ind(item) {
return this.indexOf(item);
}
exports.ind = ind;
function lstInd(item) {
return this.lastIndexOf(item);
}
exports.lstInd = lstInd;
function inArray(item) {
return this.includes(item);
}
exports.inArray = inArray;
function forE(callback) {
for (let i = 0; i < this.length; i++) {
callback(this[i], i, this);
}
}
exports.forE = forE;
function rdc(callback, initialValue) {
let accumulator = initialValue !== undefined ? initialValue : this[0];
for (let i = initialValue !== undefined ? 0 : 1; i < this.length; i++) {
accumulator = callback(accumulator, this[i], i, this);
}
return accumulator;
}
exports.rdc = rdc;
function rdcR(callback, initialValue) {
let accumulator = initialValue !== undefined ? initialValue : this[this.length - 1];
for (let i = this.length - 2; i >= 0; i--) {
accumulator = callback(accumulator, this[i], i, this);
}
return accumulator;
}
exports.rdcR = rdcR;
function fndInd(callback) {
for (let i = 0; i < this.length; i++) {
if (callback(this[i], i, this)) {
return i;
}
}
return -1;
}
exports.fndInd = fndInd;
Array.prototype.add = add;
Array.prototype.ind = ind;
Array.prototype.lstInd = lstInd;
Array.prototype.inArray = inArray;
Array.prototype.forE = forE;
Array.prototype.rdc = rdc;
Array.prototype.rdcR = rdcR;
Array.prototype.fndInd = fndInd;
;