Comments (11)
实际上通过join一个空数组得到的字符串长度是比数组长度少1位的,所以这样方法得到的字符串比传入的长度少一位
from fe-advanced-interview.
@shengxinjing @lwhhhh 微博用户“哦胖茶”的微博给了js引擎的源码地址,实现方式是 rope (tree)算法,能够做到常数级拼接。
from fe-advanced-interview.
二分法的分析是有问题的,如果不是拼接而仅仅如快速幂一样只使用加法和乘法等常数时间操作的运算,这样是可以到 Theta(log n),但是因为这里是字符串拼接,如果用vector(js里面的array)来存储,那么前拼接就要O(n),这样算起来,你所说的二分法还是Theta(n).
from fe-advanced-interview.
@AbnerZheng 他里面的二分法代码并没有使用array来存储字符串
from fe-advanced-interview.
@AbnerZheng 求指教,我代码里 应该没用array存储数据 求更好性能的代码
from fe-advanced-interview.
@shengxinjing @lwhhhh 是我想当然了,js引擎下的字符串还不是数组存储的,套了C++的了,测试了一下还是Theta(log n )
from fe-advanced-interview.
@shengxinjing thx~
from fe-advanced-interview.
@AbnerZheng 非常感谢,这个好牛逼,还真没看过js引擎的源码,Thanks
from fe-advanced-interview.
是的,同意楼上的说法,join 方法得到的字符串确实比 len 少 1
from fe-advanced-interview.
JS的位移不是很烂吗?我记得JS的所有数字都是浮点数,而JS的位移操作是按java的实现的,要把数字转换成整数才能位移啊?
from fe-advanced-interview.
位运算的性能不一定高
from fe-advanced-interview.
Related Issues (20)
- 导航有bug HOT 1
- 【开源自荐】推荐一个每日更新的前端面试题库
- 站点图片不可见
- 直播问题汇总答疑 | 蜗牛老湿的个人网站 HOT 2
- 直播面试资料整理 | 蜗牛老湿的个人网站 HOT 1
- 一个前端工程师的毕业七年总结 | 蜗牛老湿的个人网站
- 蜗牛老湿的个人网站 HOT 3
- Vue青铜-入门和组件化通信 | 蜗牛老湿的个人网站 HOT 1
- React源码教程 | 蜗牛老湿的个人网站 HOT 1
- 区块链系列教程(面向前端) | 蜗牛老湿的个人网站
- 用nodejs 构建自己的迷你区块链 | 蜗牛老湿的个人网站
- 一个前端工程师的毕业七年总结 | 蜗牛老湿的个人网站
- Vue秩序白银 --使用vuex管理数据 | 蜗牛老湿的个人网站 HOT 2
- Vue荣耀黄金 —构建自己的Router | 蜗牛老湿的个人网站 HOT 1
- 2019行动计划 | 蜗牛老湿的个人网站 HOT 1
- 2020行动计划 | 蜗牛老湿的个人网站 HOT 1
- 安全发微博 | 蜗牛老湿的个人网站
- 蜗牛老湿的个人网站
- dev HOT 4
- 运维项目1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fe-advanced-interview.