Array.from()
的时间复杂度是多少? .例如:
const set = new Set();
set.add('car');
set.add('cat');
set.add('dog');
console.log(Array.from(set)); // time complexity of making this convertion from Set to Array
最佳答案
它是 O(n)
.当用于可迭代对象(如 Set
)时,Array.from
遍历可迭代对象并将返回的每个项目放入新数组中,因此可迭代对象返回的每个项目都有一个操作。
关于javascript - Array.from 的时间复杂度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59172980/