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
const flatten = (source) => { | |
const length = source.length | |
let i = 0 | |
let flattened = [] | |
for (; i < length; i++) { | |
// recursive call could reach stack limit | |
flattened = flattened.concat( | |
!Array.isArray(source[i]) ? source[i] : flatten(source[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
import assert from 'assert' | |
const sortByAge = (source) => source.sort((itemA, itemB) => itemA.age - itemB.age) | |
const ob = (age) => ({ name: ''+age, age }) | |
assert.deepEqual( | |
sortByAge([ ob(1), ob(6), ob(2), ob(5), ob(3), ob(4) ]), | |
[ ob(1), ob(2), ob(3), ob(4), ob(5), ob(6) ] | |
) |
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 { Switch, Route } from 'react-router' | |
import { replace } from 'react-router-redux' | |
@connect(null, { replace }) | |
class PrivateRoute extends React.Component { | |
componentWillMount() { | |
this.props.replace('/foo') | |
} | |
render() { |
OlderNewer