Created
January 30, 2018 03:14
-
-
Save mrxf/f27216ab5608df697e5a5e22683e7b4f to your computer and use it in GitHub Desktop.
compare two differ between two Array
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 lastMonthData = [ | |
{ | |
id: 1, | |
name: "Alex", | |
salary: 15662 | |
}, | |
{ | |
id: 2, | |
name: "Tom", | |
salary: 18672 | |
}, | |
{ | |
id: 3, | |
name: "Smith", | |
salary: 14001 | |
} | |
] | |
const thisMonthData = [ | |
{ | |
id: 1, | |
name: "Alex", | |
salary: 19901 | |
}, | |
{ | |
id: 2, | |
name: "Tom", | |
salary: 18672 | |
}, | |
{ | |
id: 3, | |
name: "Smith", | |
salary: 11001 | |
} | |
] | |
/** | |
* 只获取薪水增加的员工 | |
* Only get staffs who was increase in salary | |
**/ | |
const luckyDogs = thisMonthData.filter(tMonth => { | |
return lastMonthData.filter(lMonth => { | |
return (tMonth.id === lMonth.id && tMonth.salary <= lMonth.salary); | |
}).length === 0; | |
}) | |
/** | |
* 获取所有调整过员工的信息 | |
**/ | |
const adjustedStaffs = thisMonthData.filter(tMonth => { | |
return lastMonthData.filter(lMonth => { | |
return (tMonth.id === lMonth.id && tMonth.salary === lMonth.salary); | |
}).length === 0; | |
}) | |
console.log(luckyDogs); | |
console.log(adjustedStaffs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment