Skip to content

at #15

Description

@customcommander

at(i, x)

Returns value at given key, index or path in an array or object or combination of both.

Where:

  • i is a string, a number or an array of strings or numbers
  • x is either an array or an object

Examples

Value from an array

at(1)([41, 42, 43]);
//=> 42

Value from a object

at('answer')({answer: 42});
//=> 42

Value from a nested array

at([1, 1])([[31, 32], [41, 42]]);
//=> 42

Value from an object in a nested array

at([1, 'answer'])([[{}], [{answer: 42}]]);
//=> 42

Features

  • Function must be curried.
  • When given an array recursively go down x
  • Should avoid null pointer exception by conceding as soon as nil (i.e. either null or undefined) is detected.
  • Return either nil or the value at i.
  • Should not read from the prototype e.g. at('length', [1, 2, 3]) should return undefined not 3.

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