Get by Path

Write a function that returns the value at a give path

function getByPath ([first, ...rest], obj)  {
  if(!first || !obj[first]) {
    // Either no path was supplied or the top-level property doesn't' exist in obj
    return undefined;
  }

  if (rest.length < 1) {
    return obj[first];
  } else {
    return getByPath(rest, obj[first]);
  }
}


let testObj = {
  foo: 2,
  bar: 'car',
  baz: {x: 'xx', y: 'yy', biz: {a: 56}}
};
getByPath(['baz', 'biz', 'a'], testObj); //56