Commit 6246d78b authored by Tristan Cavelier's avatar Tristan Cavelier

util: indexOf, min and max removed

They were useless because native method Array.prototype.indexOf,
Math.min and Math.max do the same thing.
parent 0c33f817
......@@ -746,7 +746,7 @@
"message": "Removing all associated attachments",
"loaded": o.count,
"total": o.nb_requests,
"percentage": jIO.util.min(
"percentage": Math.min(
o.count / o.nb_requests * 20 + 80,
100
)
......@@ -898,7 +898,7 @@
"message": "Getting all documents metadata",
"loaded": o.count,
"total": o.nb_requests,
"percentage": jIO.util.min(
"percentage": Math.min(
o.count / o.nb_requests * 80 + 20,
100
)
......
......@@ -506,10 +506,10 @@
var that = this, result;
function referenceAttachment(param, attachment) {
if (jIO.util.indexOf(param.referenced_attachments, attachment) !== -1) {
if (param.referenced_attachments.indexOf(attachment) !== -1) {
return;
}
var i = jIO.util.indexOf(param.unreferenced_attachments, attachment);
var i = param.unreferenced_attachments.indexOf(attachment);
if (i !== -1) {
param.unreferenced_attachments.splice(i, 1);
}
......@@ -518,10 +518,10 @@
}
function attachmentFound(param, attachment) {
if (jIO.util.indexOf(param.referenced_attachments, attachment) !== -1) {
if (param.referenced_attachments.indexOf(attachment) !== -1) {
return;
}
if (jIO.util.indexOf(param.unreferenced_attachments, attachment) !== -1) {
if (param.unreferenced_attachments.indexOf(attachment) !== -1) {
return;
}
param.unreferenced_attachments[param.unreferenced_attachments.length] =
......
......@@ -160,24 +160,6 @@ function dictFilter(dict, keys) {
}
exports.util.dictFilter = dictFilter;
/**
* A faster version of `array.indexOf(value)` -> `indexOf(value, array)`
*
* @param {Any} value The value to search for
* @param {Array} array The array to browse
* @return {Number} index of value, -1 otherwise
*/
function indexOf(value, array) {
var i;
for (i = 0; i < array.length; i += 1) {
if (array[i] === value) {
return i;
}
}
return -1;
}
exports.util.indexOf = indexOf;
/**
* Gets all elements of an array and classifies them in a dict of array.
* Dict keys are element types, and values are list of element of type 'key'.
......@@ -217,40 +199,6 @@ function generateUuid() {
}
exports.util.generateUuid = generateUuid;
/**
* Returns the number with the lowest value
*
* @param {Number} *values The values to compare
* @return {Number} The minimum
*/
function min() {
var i, val;
for (i = 1; i < arguments.length; i += 1) {
if (val === undefined || val > arguments[i]) {
val = arguments[i];
}
}
return val;
}
exports.util.min = min;
/**
* Returns the number with the greatest value
*
* @param {Number} *values The values to compare
* @return {Number} The maximum
*/
function max() {
var i, val;
for (i = 1; i < arguments.length; i += 1) {
if (val === undefined || val < arguments[i]) {
val = arguments[i];
}
}
return val;
}
exports.util.max = max;
/**
* JSON stringify a value. Dict keys are sorted in order to make a kind of
* deepEqual thanks to a simple strict equal string comparison.
......
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayInsert, indexOf, deepClone, defaults, restCommandRejecter */
/*global arrayInsert, deepClone, defaults */
// creates
// - some defaults job rule actions
......@@ -89,7 +89,7 @@ function enableJobChecker(jio, shared, options) {
// wrong single property
return;
}
if (indexOf(job_rule.action, shared.job_rule_action_names) === -1) {
if (shared.job_rule_action_names.indexOf(job_rule.action) === -1) {
// wrong action
return;
}
......
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global setTimeout, Job, createStorage, deepClone, min, restCommandResolver,
/*global setTimeout, Job, createStorage, deepClone, restCommandResolver,
restCommandRejecter */
function enableJobExecuter(jio, shared) { // , options) {
......
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayExtend, localStorage, Workspace, uniqueJSONStringify, JobQueue,
constants, indexOf, setTimeout, clearTimeout */
constants, setTimeout, clearTimeout */
function enableJobQueue(jio, shared, options) {
......
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayExtend, setTimeout, methodType, min, constants */
/*global arrayExtend, setTimeout, methodType, constants */
function enableJobRetry(jio, shared, options) {
......@@ -106,7 +106,7 @@ function enableJobRetry(jio, shared, options) {
param.modified = new Date();
shared.emit('job:modified', param);
shared.emit('job:start', param);
}, min(10000, param.tried * 2000));
}, Math.min(10000, param.tried * 2000));
} else {
shared.emit('job:reject', param, args);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment