Created
May 29, 2019 03:57
-
-
Save bcuz/eb00ad1738b292af7fc9bc257c715e6a 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
var arrayOfObjects = [ | |
{ | |
name: 'Diana', | |
born: 1373925600000, // Mon, Jul 15 2013 | |
num: 4, | |
sex: 'female' | |
}, | |
{ | |
name: 'Doris', | |
born: 1354412087000, // Sat, Dec 1 2012 | |
num: 1, | |
sex: 'female' | |
}, | |
{ | |
name: 'Beyonce', | |
born: 1366832953000, // Wed, Apr 24 2013 | |
num: 2, | |
sex: 'female' | |
}, | |
{ | |
name: 'Albert', | |
born: 1370288700000, // Mon, Jun 3 2013 | |
num: 3, | |
sex: 'male' | |
}, | |
]; | |
function hi(sorter, range) { | |
var copyArr = arrayOfObjects.slice(0); | |
copyArr.sort(function(a,b) {return (a[sorter] > b[sorter]) ? 1 : ((b[sorter] > a[sorter]) ? -1 : 0);} ); | |
const result = copyArr.filter(obj => obj.num >= range[0] && obj.num <= range[1]); | |
console.log(result); | |
} | |
hi("name", [1,2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment