Skip to content

Commit

Permalink
update: 完成pullAll
Browse files Browse the repository at this point in the history
  • Loading branch information
HeftyKoo committed Dec 30, 2019
1 parent edf6ce8 commit 160352d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
* [toInteger](toInteger.md)
* [lastIndexOf](lastIndexOf.md)
* [nth](nth.md)
* [pullAll](pullAll.md)

## License

Expand Down
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@
+ [toInteger](toInteger.md)
+ [lastIndexOf](lastIndexOf.md)
+ [nth](nth.md)
+ [pullAll](pullAll.md)
49 changes: 49 additions & 0 deletions pullAll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# lodash源码分析之pullAll

本文为读 lodash 源码的第六十一篇,后续文章会更新到这个仓库中,欢迎 star:[pocket-lodash](https://github.com/yeyuqiudeng/pocket-lodash)

gitbook也会同步仓库的更新,gitbook地址:[pocket-lodash](https://www.gitbook.com/book/yeyuqiudeng/pocket-lodash/details)

## 依赖

```javascript
import basePullAll from './.internal/basePullAll.js'
```

[《lodash源码分析之basePullAll》](internal/basePullAll.md)

## 源码分析

```javascript
function pullAll(array, values) {
return (array != null && array.length && values != null && values.length)
? basePullAll(array, values)
: array
}
```

有了 `basePullAll` ,要实现 `pullAll` 就简单了。

其实 `pullAll` 最终调用的是 `basePullAll` ,只不过在调用之前,对 `array``values` 做了一些基本的检测。

```javascript
array != null && array.length
```

确保 `array` 有传,并且不为空

```javascript
values != null && values.length
```

确保 `values` 有传,并且不为空

如果条件不满足,则直接返回 `array` ,否则调用 `basePullAll`

## License

[署名-非商业性使用-禁止演绎 4.0 国际 (CC BY-NC-ND 4.0)](http://creativecommons.org/licenses/by-nc-nd/4.0/)

最后,所有文章都会同步发送到微信公众号上,欢迎关注,欢迎提意见: ![](https://raw.githubusercontent.com/yeyuqiudeng/resource/master/images/qrcode_front-end-article.jpg)

作者:对角另一面

0 comments on commit 160352d

Please sign in to comment.