This file contains 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
var approvedStudents = _.filter(students, isApproved) | |
_.map(approvedStudents, function (s) { return s.name }) | |
// ["John", "Luke", "Mark"] |
This file contains 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
var students = [ | |
{ name: "John", grades: [7.0, 6.9, 8.0], class: "A" }, | |
{ name: "Paul", grades: [5.0, 8.7, 3.7], class: "A" }, | |
{ name: "Luke", grades: [9.0, 8.2, 6.2], class: "B" }, | |
{ name: "Mark", grades: [6.0, 9.0, 8.4], class: "B" } | |
]; | |
var sum = function (numbers) { return _.reduce(numbers, function (sum, n) { return sum + n }, 0) } | |
var average = function (numbers) { return sum(numbers) / numbers.length } | |
var isApproved = function (student) { return average(student.grades) >= 7 } |
This file contains 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
import React from 'react' | |
// https://github.com/gaearon/babel-plugin-react-transform/issues/57 | |
export default function wrapFunctionalComponent (fc) { | |
return React.createClass({ | |
displayName: fc.Name, | |
render() { | |
return fc.apply(null, this.props) | |
} |
This file contains 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
var array = [{name: "Foo", points: 1}, {name: "Bar", points: 3}]; | |
var initial = 0; | |
var totalPoints = function (result, player) { | |
return result + player.points; | |
}; | |
var total = _.reduce(array, totalPoints, initial); | |
console.log(total) // 4 |
This file contains 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
var array = [{name: "Foo", points: 1}, {name: "Bar", points: 3}]; | |
var increasePoints = function (player) { | |
return {name: player.name, points: player.points + 1}; | |
}; | |
var newArray = _.map(array, increasePoints); | |
console.log(newArray); // [{name: "Foo", points: 2}, {name: "Bar", points: 4}] |
This file contains 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
var array = [{name: "Foo", points: 1}, {name: "Bar", points: 3}]; | |
var increasePoints = function (player) { | |
return {name: player.name, points: player.points + 1}; | |
}; | |
var newArray = []; | |
_.each(array, function (player) { | |
newArray.push(increasePoints(player)); | |
}); | |
// array is undisturbed! a little clunky, though... |
This file contains 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
var array = [{name: "Foo", points: 1}, {name: "Bar", points: 3}]; | |
var increasePoints = function (player) { | |
player.points++; | |
}; | |
_.each(array, increasePoints); // MAGIC! |
This file contains 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
var array = [{name: "Foo", points: 1}, {name: "Bar", points: 3}]; | |
var increasePoints = function (player) { | |
player.points++; | |
}; | |
var i; | |
for (i = 0; i < array.length; i++) { | |
increasePoints(array[i]); | |
} |
This file contains 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
var array = [{name: "Foo", points: 1}, {name: "Bar", points: 3}]; | |
var value, i; | |
for (i = 0; i < array.length; i++) { | |
value = array[i]; | |
value.points++; | |
} | |
console.log(array) // [{name: "Foo", points: 2}, {name: "Bar", points: 4}] |
This file contains 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
var CommentList = React.createClass({ | |
render: function() { | |
var commentNodes = this.props.data.map(function (comment) { | |
return ( | |
<Comment author={comment.author}> | |
{comment.text} | |
</Comment> | |
); | |
}); | |
return ( |