Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. /**
  2. * a utility method that will walk the object for the provided properties
  3. * safely asserting if the final property is equal to `other`
  4. * @param {Object} obj
  5. * @param {Array} steps
  6. * @param {Object} other
  7. * @returns {boolean} true only if properties exist for object to
  8. * be walked and final prop is equal to `other`
  9. */
  10. function walkEquals(obj, steps, other){
  11. if(!obj){
  12. return false;
  13. }
  14.  
  15. for(let i=0; i<steps.length; i++){
  16. const next = obj[steps[i]];
  17. if(!next){
  18. return false;
  19. }
  20. obj = next;
  21. }
  22.  
  23. return obj === other;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement