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 @@ ...@@ -746,7 +746,7 @@
"message": "Removing all associated attachments", "message": "Removing all associated attachments",
"loaded": o.count, "loaded": o.count,
"total": o.nb_requests, "total": o.nb_requests,
"percentage": jIO.util.min( "percentage": Math.min(
o.count / o.nb_requests * 20 + 80, o.count / o.nb_requests * 20 + 80,
100 100
) )
...@@ -898,7 +898,7 @@ ...@@ -898,7 +898,7 @@
"message": "Getting all documents metadata", "message": "Getting all documents metadata",
"loaded": o.count, "loaded": o.count,
"total": o.nb_requests, "total": o.nb_requests,
"percentage": jIO.util.min( "percentage": Math.min(
o.count / o.nb_requests * 80 + 20, o.count / o.nb_requests * 80 + 20,
100 100
) )
......
...@@ -506,10 +506,10 @@ ...@@ -506,10 +506,10 @@
var that = this, result; var that = this, result;
function referenceAttachment(param, attachment) { function referenceAttachment(param, attachment) {
if (jIO.util.indexOf(param.referenced_attachments, attachment) !== -1) { if (param.referenced_attachments.indexOf(attachment) !== -1) {
return; return;
} }
var i = jIO.util.indexOf(param.unreferenced_attachments, attachment); var i = param.unreferenced_attachments.indexOf(attachment);
if (i !== -1) { if (i !== -1) {
param.unreferenced_attachments.splice(i, 1); param.unreferenced_attachments.splice(i, 1);
} }
...@@ -518,10 +518,10 @@ ...@@ -518,10 +518,10 @@
} }
function attachmentFound(param, attachment) { function attachmentFound(param, attachment) {
if (jIO.util.indexOf(param.referenced_attachments, attachment) !== -1) { if (param.referenced_attachments.indexOf(attachment) !== -1) {
return; return;
} }
if (jIO.util.indexOf(param.unreferenced_attachments, attachment) !== -1) { if (param.unreferenced_attachments.indexOf(attachment) !== -1) {
return; return;
} }
param.unreferenced_attachments[param.unreferenced_attachments.length] = param.unreferenced_attachments[param.unreferenced_attachments.length] =
......
...@@ -160,24 +160,6 @@ function dictFilter(dict, keys) { ...@@ -160,24 +160,6 @@ function dictFilter(dict, keys) {
} }
exports.util.dictFilter = dictFilter; 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. * 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'. * Dict keys are element types, and values are list of element of type 'key'.
...@@ -217,40 +199,6 @@ function generateUuid() { ...@@ -217,40 +199,6 @@ function generateUuid() {
} }
exports.util.generateUuid = 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 * JSON stringify a value. Dict keys are sorted in order to make a kind of
* deepEqual thanks to a simple strict equal string comparison. * deepEqual thanks to a simple strict equal string comparison.
......
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */ /*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayInsert, indexOf, deepClone, defaults, restCommandRejecter */ /*global arrayInsert, deepClone, defaults */
// creates // creates
// - some defaults job rule actions // - some defaults job rule actions
...@@ -89,7 +89,7 @@ function enableJobChecker(jio, shared, options) { ...@@ -89,7 +89,7 @@ function enableJobChecker(jio, shared, options) {
// wrong single property // wrong single property
return; 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 // wrong action
return; return;
} }
......
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */ /*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 */ restCommandRejecter */
function enableJobExecuter(jio, shared) { // , options) { function enableJobExecuter(jio, shared) { // , options) {
......
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */ /*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayExtend, localStorage, Workspace, uniqueJSONStringify, JobQueue, /*global arrayExtend, localStorage, Workspace, uniqueJSONStringify, JobQueue,
constants, indexOf, setTimeout, clearTimeout */ constants, setTimeout, clearTimeout */
function enableJobQueue(jio, shared, options) { function enableJobQueue(jio, shared, options) {
......
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */ /*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) { function enableJobRetry(jio, shared, options) {
...@@ -106,7 +106,7 @@ function enableJobRetry(jio, shared, options) { ...@@ -106,7 +106,7 @@ function enableJobRetry(jio, shared, options) {
param.modified = new Date(); param.modified = new Date();
shared.emit('job:modified', param); shared.emit('job:modified', param);
shared.emit('job:start', param); shared.emit('job:start', param);
}, min(10000, param.tried * 2000)); }, Math.min(10000, param.tried * 2000));
} else { } else {
shared.emit('job:reject', param, args); 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