Created
November 12, 2015 02:21
-
-
Save renren89/761e966b4e5e7acc05fa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
it('sorts by given value of properties', () => { | |
const state = [ | |
{ name: 'Edward', value: 21 }, | |
{ name: 'Sharpe', value: 37 }, | |
{ name: 'And', value: 45 }, | |
{ name: 'The', value: -12 }, | |
{ name: 'Magnetic' }, | |
{ name: 'Zeros', value: 37 } | |
]; | |
const nextState = state.sort( (a,b) => { | |
if ( a.value == b.value ) return 0; | |
if ( a.value < b.value ) return -1; | |
return 1; | |
}); | |
console.log(JSON.stringify(nextState, null, 2)); | |
const newState = [ | |
{ name: 'Magnetic' }, | |
{ name: 'The', value: -12 }, | |
{ name: 'Edward', value: 21 }, | |
{ name: 'Sharpe', value: 37 }, | |
{ name: 'Zeros', value: 37 }, | |
{ name: 'And', value: 45 } | |
]; | |
expect(nextState).to.deep.equal(newState); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment