javascript内置split函数的Big O

编程入门 行业动态 更新时间:2024-10-27 20:25:03
本文介绍了javascript内置split函数的Big O的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

示例:

var string = "abcde"; var array = string.split(""); // array = ["a", "b", "c", "d", "e"]

此拆分功能的摊销运行时间是多少?另外,如何在javascript中查看此类内置函数的源代码?

What is the amortized running time of this split function? Also, how do I view source code of such built-in functions in javascript?

推荐答案

使用空的定界符参数,split本质上等效于:

With an empty delimiter argument, split is essentially equivalent to:

var len = string.length; var result = Array(len) for (i = 0; i < len; i++) { result[i] = string[i]; }

这是O(len).

使用定界符,它将变为O(string.length * delimiter.length),因为在循环的每个步骤中,它都必须测试delimiter是否匹配.

With a delimiter, it becomes O(string.length * delimiter.length), because at each step in the loop it has to test whether there's a match for delimiter.

更多推荐

javascript内置split函数的Big O

本文发布于:2023-11-30 05:54:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648937.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   javascript   split   Big

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!