Skip to content

Commit f034a20

Browse files
committed
1.4.0
1 parent 2d67f34 commit f034a20

File tree

4 files changed

+55
-45
lines changed

4 files changed

+55
-45
lines changed

dist/browser/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node/array/index.js

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,71 @@
11
"use strict";
22

3+
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
4+
35
Array.prototype.insert = function (index) {
4-
index = Math.min(index, this.length);
5-
arguments.length > 1 && this.splice.apply(this, [index, 0].concat([].pop.call(arguments))) && this.insert.apply(this, arguments);
6-
return this;
6+
index = Math.min(index, this.length);
7+
arguments.length > 1 && this.splice.apply(this, [index, 0].concat([].pop.call(arguments))) && this.insert.apply(this, arguments);
8+
return this;
79
};
810

911
Array.prototype.remove = function () {
10-
var _arguments = arguments,
11-
_this = this;
12-
13-
// If no arguments passed into remove function
14-
if (arguments.length <= 0) {
15-
// Should do nothing
16-
return this;
17-
}
18-
delete arguments.length;
19-
var indexesToRemove = Object.keys(arguments).map(function (key) {
20-
return _arguments[key];
21-
}).sort(function (a, b) {
22-
return b - a; // sort descending order
23-
});
24-
indexesToRemove.forEach(function (index) {
25-
if (_this[index] != undefined && _this[index] != null && index >= 0 && index < _this.length) {
26-
_this.splice(index, 1);
27-
}
28-
});
29-
return this;
12+
var _arguments = arguments,
13+
_this = this;
14+
15+
// If no arguments passed into remove function
16+
if (arguments.length <= 0) {
17+
// Should do nothing
18+
return this;
19+
}
20+
delete arguments.length;
21+
var indexesToRemove = Object.keys(arguments).map(function (key) {
22+
return _arguments[key];
23+
}).sort(function (a, b) {
24+
return b - a; // sort descending order
25+
});
26+
indexesToRemove.forEach(function (index) {
27+
if (_this[index] != undefined && _this[index] != null && index >= 0 && index < _this.length) {
28+
_this.splice(index, 1);
29+
}
30+
});
31+
return this;
3032
};
3133

3234
Array.prototype.shuffle = function () {
33-
var currentIndex = this.length;
34-
var temporaryValue;
35-
var randomIndex;
35+
var currentIndex = this.length;
36+
var temporaryValue;
37+
var randomIndex;
3638

37-
while (0 !== currentIndex) {
38-
randomIndex = Math.floor(Math.random() * currentIndex);
39-
currentIndex -= 1;
39+
while (0 !== currentIndex) {
40+
randomIndex = Math.floor(Math.random() * currentIndex);
41+
currentIndex -= 1;
4042

41-
temporaryValue = this[currentIndex];
42-
this[currentIndex] = this[randomIndex];
43-
this[randomIndex] = temporaryValue;
44-
}
43+
temporaryValue = this[currentIndex];
44+
this[currentIndex] = this[randomIndex];
45+
this[randomIndex] = temporaryValue;
46+
}
4547

46-
return this;
48+
return this;
4749
};
4850

4951
Array.prototype.randomElement = function () {
50-
return this[Math.floor(Math.random() * this.length)];
52+
return this[Math.floor(Math.random() * this.length)];
5153
};
5254

5355
Array.prototype.swap = function (a, b) {
54-
if (!this[a] || !this[b]) {
55-
return this;
56-
}
57-
var tmp = this[a];
58-
this[a] = this[b];
59-
this[b] = tmp;
60-
return this;
56+
if (!this[a] || !this[b]) {
57+
return this;
58+
}
59+
var tmp = this[a];
60+
this[a] = this[b];
61+
this[b] = tmp;
62+
return this;
63+
};
64+
65+
Array.prototype.max = function () {
66+
return Math.max.apply(Math, _toConsumableArray(this));
67+
};
68+
69+
Array.prototype.min = function () {
70+
return Math.min.apply(Math, _toConsumableArray(this));
6171
};

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scriptutils",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"description": "Utilities to make Javascript Easy",
55
"main": "dist/node/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)