customcommander / customcommander/functionaut

at

Open
#15 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

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

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

### Value from a object

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

### Value from a nested array

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

### Value from an object in a nested array

```javascript
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`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.