Preparation Code Preparation HTML (this will be inserted in the <body>
of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src ="https://code.jquery.com/jquery-2.1.1.min.js" > </script >
<script src ="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js" > </script >
Setup JS var testArray = [0 , 10 , 11 , 9 , 924 , 19238 , 1248 , 8 , 0 , 0 , 2 , -1 , -5 ];
var _getArrayMin = function (array ) {
var min = Infinity ;
_.each (array, function (val ) {
if (min > val) {
min = val;
}
});
return min;
}
var nativeForeachGetArrayMin = function (array ) {
var min = Infinity ;
array.forEach (function (val ) {
if (min > val) {
min = val;
}
});
return min;
}
var $getArrayMin = function (array ) {
var min = Infinity ;
$.each (array, function (key, val ) {
if (min > val) {
min = val;
}
});
return min;
}
var forGetArrayMin = function (array ) {
var i = 0 ,
min = array[i++],
len = array.length ,
val;
for (;i < len; i++) {
val = array[i];
if (min > val) {
min = val;
}
}
return min;
}
var forInGetArrayMin = function (array ) {
var min = array[i++],
len = array.length ,
val;
for (var i in array) {
val = array[i];
if (min > val) {
min = val;
}
}
return min;
}
var whileGetArrayMin = function (array ) {
var i = 0 ,
min = array[i++],
len = array.length ,
val;
while (i < len) {
val = array[i++];
if (min > val) {
min = val;
}
}
return min;
}
Teardown JS