Skip to content

李鹏#32

Open
freewind wants to merge 4 commits into
tws-practice:masterfrom
freewind:demo-new-method
Open

李鹏#32
freewind wants to merge 4 commits into
tws-practice:masterfrom
freewind:demo-new-method

Conversation

@freewind

Copy link
Copy Markdown

implemented 7 specs

@xudaye

xudaye commented Jul 29, 2016

Copy link
Copy Markdown

已占作

@lidan-summer

Copy link
Copy Markdown

我要占坑

@maruiqi

maruiqi commented Jul 29, 2016

Copy link
Copy Markdown

占坑

@ZT1996

ZT1996 commented Jul 29, 2016

Copy link
Copy Markdown

板凳已占

@AmberYLopez

Copy link
Copy Markdown

火钳留名

@Aym-fuhong

Copy link
Copy Markdown

占坑

return _(collection)
.filter(x => x%2==0)
.map(x => x - 1)
.map(x => "a".charCodeAt(0) + x)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以直接给x+96,感觉更简单点

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,这也是一种思路,但是需要说明96是从哪里来的

@duanCoin

Copy link
Copy Markdown

占满也要看


//在这里写入代码
function hybrid_operation(collection) {
return _(collection).map(x => x*3+2).sum();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥不写成_.chain(collection).map(x => x*3+2).sum().value();?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么时候用.value()?我输出是乱七八遭的时候会加value.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一般——chian()链加value(),有sum(),mean()等结果是数字的不用加

@Aym-fuhong Aym-fuhong Jul 29, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_(collection).map(x => x*3+2).sum()_chian(collection).map(x => x*3+2).sum().value()是等价的

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

明白了,value()是把前面包装的壳儿卸了。。所以专业的说法也不懂

@FishNon

FishNon commented Jul 29, 2016

Copy link
Copy Markdown

搬着小椅子占

//在这里写入代码
function average_to_letter(collection) {
let sum = _.sum(collection);
let average = Math.ceil(sum/collection.length);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let average = .ceil(.mean(collection));

@lidan-summer lidan-summer Jul 29, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let total = _.mean(collection);
let dev = _.ceil(total);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更好的做法是先chain,再调用mean和ceil,感谢同学们指出:

_.chain(collection).sum().ceil().value()

@Liuhaiyan6

Copy link
Copy Markdown

占座

function average_uneven(collection) {
let odds = _.filter(collection, x=>x%2===1);
let sum = _.sum(odds);
return sum/odds.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这三行可以直接简写为return _.chain(collection).filter(x =>x%2===1).mean().value();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.