1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| var arr1=[1,5,3,7,9]; var arr2=[2,4,8,6,10]; var arr3=[1,2,3,6,9]; if(Array.prototype.every===undefined){ Array.prototype.every=function(call){ for(var i=0;i<this.length;i++){ if(i in this){ var r=call(this[i],i,this) if(!r){ return false} } } return true } }; if(Array.prototype.some===undefined){ Array.prototype.some=function(call){ for(var i=0;i<this.length;i++){ if(i in this){ var r=call(this[i],i,this) if(!r){ return true} } } return false } }; console.log( arr1.every(function(val){ return val%2==1 })+"<br>"+ arr2.every(function(val){ return val%2==1 })+"<br>"+ arr3.every(function(val){ return val%2==1 }) ); console.log( arr1.some(function(val){ return val%2==1 })+"<br>"+ arr2.some(function(val){ return val%2==1 })+"<br>"+ arr3.some(function(val){ return val%2==1 }) )
console.log( arr1.every(function(val,idx,arr){ return idx<arr.length-1?val<=arr[idx+1]:true })+"<br>"+ arr2.every(function(val,idx,arr){ return idx<arr.length-1?val<=arr[idx+1]:true })+"<br>"+ arr3.every(function(val,idx,arr){ return idx<arr.length-1?val<=arr[idx+1]:true }) );
|