Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

at #15

Open
Open
at #15

Description

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.

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

        AltStyle によって変換されたページ (->オリジナル) /