I have an Array ( key, startValue , EndValue);
var fruits = [[1,10, 15], [1,25, 30]];
i want to Validate before Push
console.log(push([1,5, 35])); // false
console.log(push([2,5, 35])); // true
console.log(push([1,30, 40])); // true
console.log(push([1,15, 25])); // true
console.log(push([1,5, 10])); // true
console.log(fruits);
Similarly i have key 2,3,4,5, ect.
i am working with below Script.
function push(array) {
return fruits.every(function(a) {
return array[0] == a[0] && (array[2] <= a[1] || a[2] <= array[1]);
}) && fruits.push(array) && true;
}
console.log(push([2,5, 35])); // truetrue?console.log(push([2,5, 35]));you want this to be true instead of false ?