Skip to content

Commit 160352d

Browse files
committed
update: 完成pullAll
1 parent edf6ce8 commit 160352d

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
* [toInteger](toInteger.md)
8585
* [lastIndexOf](lastIndexOf.md)
8686
* [nth](nth.md)
87+
* [pullAll](pullAll.md)
8788

8889
## License
8990

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@
6363
+ [toInteger](toInteger.md)
6464
+ [lastIndexOf](lastIndexOf.md)
6565
+ [nth](nth.md)
66+
+ [pullAll](pullAll.md)

pullAll.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# lodash源码分析之pullAll
2+
3+
本文为读 lodash 源码的第六十一篇,后续文章会更新到这个仓库中,欢迎 star:[pocket-lodash](https://github.com/yeyuqiudeng/pocket-lodash)
4+
5+
gitbook也会同步仓库的更新,gitbook地址:[pocket-lodash](https://www.gitbook.com/book/yeyuqiudeng/pocket-lodash/details)
6+
7+
## 依赖
8+
9+
```javascript
10+
import basePullAll from './.internal/basePullAll.js'
11+
```
12+
13+
[《lodash源码分析之basePullAll》](internal/basePullAll.md)
14+
15+
## 源码分析
16+
17+
```javascript
18+
function pullAll(array, values) {
19+
return (array != null && array.length && values != null && values.length)
20+
? basePullAll(array, values)
21+
: array
22+
}
23+
```
24+
25+
有了 `basePullAll` ,要实现 `pullAll` 就简单了。
26+
27+
其实 `pullAll` 最终调用的是 `basePullAll` ,只不过在调用之前,对 `array``values` 做了一些基本的检测。
28+
29+
```javascript
30+
array != null && array.length
31+
```
32+
33+
确保 `array` 有传,并且不为空
34+
35+
```javascript
36+
values != null && values.length
37+
```
38+
39+
确保 `values` 有传,并且不为空
40+
41+
如果条件不满足,则直接返回 `array` ,否则调用 `basePullAll`
42+
43+
## License
44+
45+
[署名-非商业性使用-禁止演绎 4.0 国际 (CC BY-NC-ND 4.0)](http://creativecommons.org/licenses/by-nc-nd/4.0/)
46+
47+
最后,所有文章都会同步发送到微信公众号上,欢迎关注,欢迎提意见: ![](https://raw.githubusercontent.com/yeyuqiudeng/resource/master/images/qrcode_front-end-article.jpg)
48+
49+
作者:对角另一面

0 commit comments

Comments
 (0)