javascript Array.prototype.filter()的时间复杂度?

Array.protoype.filter的大O是什么?

我查看了文档(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),但一直无法解决.

最佳答案 上)

例:

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;
}

输出:

“called”
“called”
“called”
“called”
“called”
“called”
Array [“exuberant”, “destruction”, “present”]

点赞