Skip to content

Commit efc7829

Browse files
committed
Merge pull request facebook#2330 from alexeyraspopov/patch-1
use function composition instead of mutable state
2 parents 7853aff + 1db3ed0 commit efc7829

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

examples/ballmer-peak/example.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function computeBallmerPeak(x) {
1010
) / 1.6;
1111
}
1212

13+
function percentage(x) {
14+
return isNaN(x) ? 'N/A' : (100 - Math.round(x * 100)) + '%';
15+
}
16+
1317
var BallmerPeakCalculator = React.createClass({
1418
getInitialState: function() {
1519
return {bac: 0};
@@ -18,12 +22,7 @@ var BallmerPeakCalculator = React.createClass({
1822
this.setState({bac: event.target.value});
1923
},
2024
render: function() {
21-
var pct = computeBallmerPeak(this.state.bac);
22-
if (isNaN(pct)) {
23-
pct = 'N/A';
24-
} else {
25-
pct = (100 - Math.round(pct * 100)) + '%';
26-
}
25+
var pct = percentage(computeBallmerPeak(this.state.bac));
2726
return (
2827
<div>
2928
<img src="./ballmer_peak.png" />

0 commit comments

Comments
 (0)