I need help with coding.
I need to filter 14 values from an array. The values are created dynamically. I want to compare values to 20.0 I only need two of the values to be higher than 20.0
I put my hopes into filter
method as Switch did not work.
Thank you in advance!
if (!Array.prototype.filter) {
Array.prototype.filter = function (fun /*, thisp*/) {
var len = this.length;
if (typeof fun != "function")
throw new TypeError();
var res = new Array();
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in this) {
var val = this[i]; // in case fun mutates this
if (fun.call(thisp, val, i, this))
res.push(val);
}
}
return res;
};
}
function isBigEnough(element, index, array) {
return (filtered >= 20.0);
}
var filtered = [
(vol1l * 100).toFixed(1),
(vol2l * 100).toFixed(1),
(vol3l * 100).toFixed(1),
(vol4l * 100).toFixed(1),
(vol5l * 100).toFixed(1),
(vol6l * 100).toFixed(1),
(vol7l * 100).toFixed(1),
(vol1r * 100).toFixed(1),
(vol2r * 100).toFixed(1),
(vol3r * 100).toFixed(1),
(vol4r * 100).toFixed(1),
(vol5r * 100).toFixed(1),
(vol6r * 100).toFixed(1),
(vol7r * 100).toFixed(1)
].filter(isBigEnough);
if (filtered) {
testText.textContent = "JA! Gerät"
} else {
testText.textContent = "NO! Nein"
}