JavaScript-Algorithms
JavaScript-Algorithms copied to clipboard
基础理论+JS框架应用+实践,从0到1构建整个前端算法体系
返回解析后的整数值。 如果被解析参数的第一个字符无法被转化成数值类型,则返回 [`NaN`](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/NaN)。 注意:`radix` 参数为 `n` 将会把第一个参数看作是一个数的 `n` 进制表示,而返回的值则是十进制的。例如: ```js parseInt('123', 5) // 将'123'看作5进制数,返回十进制数38 => 3*5^0 + 2*5^1 + 1*5^2 = 38 ``` 以下 2 进制没有问题 ```js function _parseInt(str, radix)...
```js let x = [1, 2, 3]; let y = x; let z = [4, 5, 6]; y[0] = 10; y = z; z[1] = 20; x[2] = z =...
找出一个字符串中的不匹配括号( `{[()]}` )的位置,以json形式输出,位置index从0开始。 - 异常输入 ``` ${{(3+5)*2+(5/(24)} ``` - 输出 ``` { 1: '{', 11: '(', } ``` - 正常输入 ``` [a+b]/${x} ``` - 输出 ``` {} ```
给定两个字符串形式的非负整数 `num1` 和 `num2` ,计算它们的和。 **例如:** "111" + ”2222“ = ”2333“ **注意:** - `num1` 和 `num2` 的长度都小于 `5100` - `num1` 和 `num2` 都只包含数字 `0-9` - `num1` 和 `num2` 都不包含任何前导零 -...
给你一个数组 `[2,1,2,4,3]` ,你返回数组 `[4,2,4,−1,−1]` **解释:** 第一个 `2` 后面比 `2` 大的数是 `4` ; `1` 后面比 `1` 大的数是 `2` ;第二个 `2` 后面比 `2` 大的数是 `4`; `4` 后面没有比 `4` 大的数,填 `-1` ;`3` 后面没有比...
```js setTimeout(() => console.log(0)) new Promise((resolve) => { console.log(1) resolve(2) console.log(3) }).then(o => console.log(o)) new Promise(resolve => { console.log(4) resolve(5) }).then(o => console.log(o)).then(() => console.log(6)) ``` 可参考 [从一道面试题谈谈对 EventLoop 的理解](https://mp.weixin.qq.com/s/3WLuVR4NWnDUOsVQuTSYJw)
使用 API: `Object.is()` 方法判断两个值是否为同一个值 ```js Object.is(x, y) ``` Polyfill: ```js if (!Object.is) { Object.is = function(x, y) { // SameValue algorithm if (x === y) { // Steps 1-5, 7-10...
```js 移动元素函数里 判断over 2 ? argumentsLen - 2 : 0 console.log('addCount: ', addCount); //4. 计算有效的开始位置start let startIdx = computeSpliceStartIdx(start, arrayLength); //5. 计算有效的删除个数 let delCount = computeSpiceDelCount(startIdx, deleteCount, arrayLength); console.log('delCount: ',...
## splice > ``` > array.splice(start[, deleteCount[, item1[, item2[, ...]]]]) > ``` > > MDN:**splice()** 方法通过删除或替换现有元素或者原地添加新的元素来修改数组,并以数组形式返回被修改的内容。此方法会改变原数组 **[Array.prototype.splice()](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) 的用法如下:** - `array.splice(start)` :删除数组中从下标 `start` 开始(包含 `start` )的所有元素 - `array.splice(start, deleteCount)` :删除数组中从下标 `start`...