李鹏#32
Open
freewind wants to merge 4 commits into
Open
Conversation
added 2 commits
July 29, 2016 10:17
|
已占作 |
|
我要占坑 |
|
占坑 |
|
板凳已占 |
|
火钳留名 |
|
占坑 |
| return _(collection) | ||
| .filter(x => x%2==0) | ||
| .map(x => x - 1) | ||
| .map(x => "a".charCodeAt(0) + x) |
|
占满也要看 |
|
|
||
| //在这里写入代码 | ||
| function hybrid_operation(collection) { | ||
| return _(collection).map(x => x*3+2).sum(); |
There was a problem hiding this comment.
这里为啥不写成_.chain(collection).map(x => x*3+2).sum().value();?
There was a problem hiding this comment.
一般——chian()链加value(),有sum(),mean()等结果是数字的不用加
There was a problem hiding this comment.
_(collection).map(x => x*3+2).sum()和_chian(collection).map(x => x*3+2).sum().value()是等价的
|
搬着小椅子占 |
| //在这里写入代码 | ||
| function average_to_letter(collection) { | ||
| let sum = _.sum(collection); | ||
| let average = Math.ceil(sum/collection.length); |
There was a problem hiding this comment.
let average = .ceil(.mean(collection));
There was a problem hiding this comment.
let total = _.mean(collection);
let dev = _.ceil(total);
Author
There was a problem hiding this comment.
更好的做法是先chain,再调用mean和ceil,感谢同学们指出:
_.chain(collection).sum().ceil().value()
|
占座 |
| function average_uneven(collection) { | ||
| let odds = _.filter(collection, x=>x%2===1); | ||
| let sum = _.sum(odds); | ||
| return sum/odds.length; |
There was a problem hiding this comment.
这三行可以直接简写为return _.chain(collection).filter(x =>x%2===1).mean().value();
added 2 commits
July 29, 2016 14:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
implemented 7 specs