<!doctype html>
<html>
<head>
<title>标题</title>
<meta charset="utf-8">
<script>
var arr1=[1,2,3,2,1];
var arr2=[8,6,4,2,0];
var arr3=[1,3,5,7,9];
//判断是否都由偶数组成:
var r1=arr1.some(function(val){
return val%2==0;
})
var r2=arr2.some(function(val){
return val%2==0;
})
var r3=arr3.some(function(val){
return val%2==0;
})
console.log(r1,r2,r3);
//判断是否升序排列:
r1=arr1.every(function(val,idx,arr){
return idx<arr.length-1?
val<=arr[idx+1]:true;
})
r2=arr2.every(function(val,idx,arr){
return idx<arr.length-1?
val<=arr[idx+1]:true;
})
r3=arr3.every(function(val,idx,arr){
return idx<arr.length-1?
val<=arr[idx+1]:true;
})
console.log(r1,r2,r3);
</script>
</head>
<body>
</body>
</html>
javascript面向对象(十一)
最新推荐文章于 2022-08-09 15:00:06 发布