Guest User

Untitled

a guest
Jul 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. const check = ({ array, prop1, prop2 } = {}) => {
  2. if (!Array.isArray(array) || array.length === 0 ) {
  3. return;
  4. }
  5.  
  6. const lastIndex = array.length - 1;
  7. const prevIndex = array.length - 2;
  8.  
  9. const last = array[lastIndex];
  10.  
  11. const prev = array[prevIndex];
  12.  
  13. if (!prev) return;
  14.  
  15. const isMatchWithLast = last.prop1 === prop1 && last.prop2 === prop2;
  16. const isMatchWithPrev = prev.prop1 === prop1 && prev.prop2 === prop2;
  17.  
  18.  
  19.  
  20. return isMatchWithLast && isMatchWithPrev;
  21. }
Add Comment
Please, Sign In to add comment