Skip to content

130 bytes is smallest possible? #26

Description

@Danny-Engelman

If you make a statement like that you can always count on a smart ass to respond

  • p can be declared as default value
  • split('.') can be written as split`.`
  • length is used twice

How about something like:

export default dlv = (
    obj,
    key,
    def,
    p=0,
    k=key.split ? key.split`.` : key,
    l=k.length
) => {
           while (obj && p<l) obj = obj[k[p++]];
           return (obj===undefined || p<l) ? def : obj;   
}

... haven't tested it

Or to get rid of the return

export default dlv = (
    obj,
    key,
    def,
    p=0,
    k=key.split ? key.split`.` : key,
    l=k.length,
    o=(_=>{while (obj && p<l) obj = obj[k[p++]]})()
) => (obj===undefined || p<l) ? def : obj;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions