Hacker News new | ask | show | jobs
by roryokane 1121 days ago
Nice simplification of the “clever” code. Lodash docs for anyone curious: https://lodash.com/docs/4.17.15#pickBy

Here’s my version of the “clever” example that doesn’t depend on Lodash. It’s longer than your version but still simpler than the article’s:

  const extractDataFromResponse = (response) => {
    const [Component, props] = response;
    const dataIncludingUndefinedValues = { Component, props };
  
    return Object.fromEntries(
      Object.entries(dataIncludingUndefinedValues).filter(([_key, val]) => val)
    );
  };