Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"test": "jasmine-node --verbose specs"
},
"dependencies": {
"jasmine-node": "1.14.5"
"jasmine-node": "1.14.5",
"lodash": "^4.14.0"
}
}
}
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,14 @@
'use strict';

function average_to_letter(collection) {
let _ = require('lodash');

//在这里写入代码
function average_to_letter(collection) {
let diff = 'a'.charCodeAt(0) - 1;
let average = _.chain(collection)
.mean()
.ceil()
.value();
return String.fromCharCode(average + diff);
}

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()就可以串起来了

return String.fromCharCode(
      _.chain(collection)
        .mean()
        .ceil()
        .value()+96
    );

module.exports = average_to_letter;
Expand Down
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();

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()是把前面包装的壳儿卸了。。所以专业的说法也不懂

}

module.exports = hybrid_operation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
'use strict';

function hybrid_operation_to_uneven(collection) {
let _ = require('lodash');

//在这里写入代码
function hybrid_operation_to_uneven(collection) {
return _(collection)
.filter(x => x%2==1)
.map(x => x*3+2)
.value();
}

module.exports = hybrid_operation_to_uneven;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
'use strict';

function hybrid_operation_to_uneven(collection) {
let _ = require('lodash');

function hybrid_operation_to_uneven(collection) {
return _(collection)
.filter(x => x%2===1)
.map(x => x*3+5)
.sum();
//在这里写入代码
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
'use strict';

function amount_even(collection) {
let _ = require('lodash');

function amount_even(collection) {
return _(collection)
.filter(x => x%2===0)
.sum();
//在这里写入代码
}

Expand Down
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;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var even_to_letter = require("../../../practices/superposition_operation/collection_operation/letter_mapping_1.js");

describe('even_to_letter', function() {
ddescribe('even_to_letter', function() {

var collection = [1,2,3,4,5,6,7,8,9,10];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var average_to_letter = require("../../../practices/superposition_operation/collection_operation/letter_mapping_2.js");

describe('average_to_letter', function() {
ddescribe('average_to_letter', function() {

var collection = [1,2,3,4,5,6,7,8,9,10];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var hybrid_operation = require("../../../practices/superposition_operation/collection_operation/practice_1.js");

describe('hybrid_operation', function() {
ddescribe('hybrid_operation', function() {

var collection = [1,5,7,11,35,67];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var hybrid_operation_to_uneven = require("../../../practices/superposition_operation/collection_operation/practice_2.js");

describe('hybrid_operation_to_uneven', function() {
ddescribe('hybrid_operation_to_uneven', function() {

var collection = [1,5,7,12,11,35,54,67,70];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var hybrid_operation_to_uneven = require("../../../practices/superposition_operation/collection_operation/practice_3.js");

describe('hybrid_operation_to_uneven', function() {
ddescribe('hybrid_operation_to_uneven', function() {

var collection = [1,5,7,12,11,35,54,67,70];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var amount_even = require("../../../practices/superposition_operation/interval_operation/amount_even.js");

describe('amount_even', function() {
ddescribe('amount_even', function() {

var collection = [1,2,3,4,5,6,7,8,9,10];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var average_uneven = require("../../../practices/superposition_operation/interval_operation/average_uneven.js");

describe('average_uneven', function() {
ddescribe('average_uneven', function() {

var collection = [1,2,3,4,5,6,7,8,9,10];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

var median_to_letter = require("../../../practices/superposition_operation/interval_operation/average_uneven.js");
var median_to_letter = require("../../../practices/superposition_operation/interval_operation/median_to_letter.js");

describe('median_to_letter', function() {
ddescribe('median_to_letter', function() {

var collection = [20,21,22,23,24,25,26,27,28,29,
30,31,32,33,34,35,36,37,38,39,
Expand Down