Array.protoype.filter
的大O是什么?
我查看了文档(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),但还没有能够解决它。
答案 0 :(得分:2)
O(N)
示例:
var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => isBig(word));
function isBig(word){
console.log("called");
return word.length > 6;
}
输出:
“称为” “叫” “叫” “叫” “叫” “叫” 数组[“旺盛”,“破坏”,“现在”]