SHARE
TWEET

Untitled

a guest Jun 20th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var items = [
  2.   { name: 'Edward', value: 21 },
  3.   { name: 'Sharpe', value: 37 },
  4.   { name: 'And', value: 45 },
  5.   { name: 'The', value: -12 },
  6.   { name: 'Magnetic', value: 37 },
  7.   { name: 'Zeros', value: 37 }
  8. ];
  9.  
  10. // Sort by value
  11. items.sort(function (a, b) {
  12.     return a.value - b.value;
  13. });
  14.      
  15. [
  16.   { name: 'Magnetic', value: 37 },
  17.   { name: 'Sharpe', value: 37 },
  18.   { name: 'Zeros', value: 37 }
  19. ]
  20.      
  21. items.filter((i)=>{
  22.     let duplicate = items.filter((x)=> {
  23.         return x.value === i.value;
  24.     })
  25.     // Return if has duplicate
  26.     return duplicate.length > 1
  27. })
  28.      
  29. [{ name: 'Magnetic', value: 37 },  { name: 'Sharpe', value: 37 }, { name: 'Zeros', value: 37 }]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top