Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const _ = require('lodash');
- var matchingCards = [
- { title: 'steve', code: '2' },
- { title: 'noah', code: '1' },
- { title: 'noah', code: '3' },
- ];
- var latestCardsByTitle = {};
- for (var card of matchingCards) {
- var latestCard = latestCardsByTitle[card.title];
- if (!latestCard || card.code > latestCard.code) {
- latestCardsByTitle[card.title] = card;
- }
- }
- var latestCards = _.sortBy(latestCardsByTitle, 'title');
- console.log(latestCards);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement