-
Notifications
You must be signed in to change notification settings - Fork 214
李鹏 #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
李鹏 #32
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hello |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| 'use strict'; | ||
|
|
||
| function even_to_letter(collection) { | ||
| let _ = require('lodash'); | ||
|
|
||
| //在这里写入代码 | ||
| function even_to_letter(collection) { | ||
| let diff = 'a'.charCodeAt(0) - 1; | ||
| return _(collection) | ||
| .filter(x => x%2===0) | ||
| .map(x => x + diff) | ||
| .map(x => String.fromCharCode(x)) | ||
| .value(); | ||
| } | ||
|
|
||
| module.exports = even_to_letter; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| 'use strict'; | ||
|
|
||
| function hybrid_operation(collection) { | ||
| let _ = require('lodash'); | ||
|
|
||
| //在这里写入代码 | ||
| function hybrid_operation(collection) { | ||
| return _(collection).map(x => x*3+2).sum(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里为啥不写成 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 什么时候用.value()?我输出是乱七八遭的时候会加value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 一般——chian()链加value(),有sum(),mean()等结果是数字的不用加 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 明白了,value()是把前面包装的壳儿卸了。。所以专业的说法也不懂 |
||
| } | ||
|
|
||
| module.exports = hybrid_operation; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| 'use strict'; | ||
|
|
||
| function average_uneven(collection) { | ||
| let _ = require('lodash'); | ||
|
|
||
| //在这里写入代码 | ||
| function average_uneven(collection) { | ||
| return _(collection) | ||
| .filter(x=>x%2===1) | ||
| .mean(); | ||
| } | ||
|
|
||
| module.exports = average_uneven; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,24 @@ | ||
| 'use strict'; | ||
|
|
||
| function median_to_letter(collection) { | ||
| let _ = require('lodash'); | ||
|
|
||
| function _toCharNumber(charCode) { | ||
| // TODO | ||
| return 0; | ||
| } | ||
|
|
||
| //在这里写入代码 | ||
| function median_to_letter(collection) { | ||
| let median = _.chain(collection) | ||
| .sortBy() | ||
| .filter((item, index, all) => { | ||
| if(all.length%2===1) { | ||
| return index === (all.length-1)/2; | ||
| } else { | ||
| let expected = [all.length/2, all.length/2+1] | ||
| return expected.includes(index); | ||
| } | ||
| }); | ||
| return _toCharNumber(median); | ||
| } | ||
|
|
||
| module.exports = median_to_letter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用_.chain()就可以串起来了