collection(4)--every&some
2016-07-25 本文已影响7人
LuciferTM
every
如果集合里每一个元素都满足条件,则传给最终回调的result为true,否则为false。
every(arr, iterator(item,callback), callback(result))
//alias: all
另外every接口有个别名为all。
测试数据:

代码:

结果:

代码:

结果:

不知道为什么在我的机器上返回的结果为null,而非false。按照文档描述的返回结果只有两种,true/false。
some
如果说every的功能是“且”,那么some的功能就是“或”。当集合中是否有至少一个元素满足条件时,最终callback得到的值为true,否则为false。
接口:
some(arr, iterator(item,callback(test)), callback(result))
//alias: any
测试数据:

代码:

结果:

代码:

结果:
