GithubHelp home page GithubHelp logo

Comments (11)

aiyogg avatar aiyogg commented on May 20, 2024 4

实际上通过join一个空数组得到的字符串长度是比数组长度少1位的,所以这样方法得到的字符串比传入的长度少一位

from fe-advanced-interview.

AbnerZheng avatar AbnerZheng commented on May 20, 2024 3

@shengxinjing @lwhhhh 微博用户“哦胖茶”的微博给了js引擎的源码地址,实现方式是 rope (tree)算法,能够做到常数级拼接。

from fe-advanced-interview.

AbnerZheng avatar AbnerZheng commented on May 20, 2024

二分法的分析是有问题的,如果不是拼接而仅仅如快速幂一样只使用加法和乘法等常数时间操作的运算,这样是可以到 Theta(log n),但是因为这里是字符串拼接,如果用vector(js里面的array)来存储,那么前拼接就要O(n),这样算起来,你所说的二分法还是Theta(n).

from fe-advanced-interview.

lwhile avatar lwhile commented on May 20, 2024

@AbnerZheng 他里面的二分法代码并没有使用array来存储字符串

from fe-advanced-interview.

shengxinjing avatar shengxinjing commented on May 20, 2024

@AbnerZheng 求指教,我代码里 应该没用array存储数据 求更好性能的代码

from fe-advanced-interview.

AbnerZheng avatar AbnerZheng commented on May 20, 2024

@shengxinjing @lwhhhh 是我想当然了,js引擎下的字符串还不是数组存储的,套了C++的了,测试了一下还是Theta(log n )

from fe-advanced-interview.

lwhile avatar lwhile commented on May 20, 2024

@shengxinjing thx~

from fe-advanced-interview.

shengxinjing avatar shengxinjing commented on May 20, 2024

@AbnerZheng 非常感谢,这个好牛逼,还真没看过js引擎的源码,Thanks

from fe-advanced-interview.

Agcaiyun avatar Agcaiyun commented on May 20, 2024

是的,同意楼上的说法,join 方法得到的字符串确实比 len 少 1
image

from fe-advanced-interview.

shanoaice avatar shanoaice commented on May 20, 2024

JS的位移不是很烂吗?我记得JS的所有数字都是浮点数,而JS的位移操作是按java的实现的,要把数字转换成整数才能位移啊?

from fe-advanced-interview.

zhangzs000 avatar zhangzs000 commented on May 20, 2024

位运算的性能不一定高

from fe-advanced-interview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.