JQuery | function getArrayMin(array) {
var min = -1;
$.each(array, function(idx, val) {
if (min < 0 && val > 0) {
min = val;
return true;
}
if (val > 0 && min > val) {
min = val
return true;
}
});
return min;
};
getArrayMin([0, 10, 11, 9, 924, 19238, 1248, 8, 0, 0, 2, -1, -5]);
| ready |
for | function getArrayMin(array) {
var min = -1;
for (var i = 0; i < array.length; i += 1) {
var val = array[i];
if (min < 0 && val > 0) {
min = val;
continue;
}
if (val > 0 && min > val) {
min = val
continue;
}
}
return min;
};
getArrayMin([0, 10, 11, 9, 924, 19238, 1248, 8, 0, 0, 2, -1, -5]);
| ready |
_.each | function getArrayMin(array) {
var min = -1;
_.each(array, function(idx, val) {
if (min < 0 && val > 0) {
min = val;
return true;
}
if (val > 0 && min > val) {
min = val
return true;
}
});
return min;
};
getArrayMin([0, 10, 11, 9, 924, 19238, 1248, 8, 0, 0, 2, -1, -5]);
| ready |
jQuery define func outside | function getArrayMin(array) {
var min = -1;
var arrayFunc = function(idx, val) {
if (min < 0 && val > 0) {
min = val;
return true;
}
if (val > 0 && min > val) {
min = val
return true;
}
};
$.each(array, arrayFunc);
return min;
};
getArrayMin([0, 10, 11, 9, 924, 19238, 1248, 8, 0, 0, 2, -1, -5]);
| ready |
for with arr.length stored | function getArrayMin(array) {
var min = -1;
var arrL = array.length;
for (var i = 0; i < arrL; i += 1) {
var val = array[i];
if (min < 0 && val > 0) {
min = val;
continue;
}
if (val > 0 && min > val) {
min = val
continue;
}
}
return min;
};
getArrayMin([0, 10, 11, 9, 924, 19238, 1248, 8, 0, 0, 2, -1, -5]);
| ready |