API Docs for:
Show:

Utils.Array Class

Provides array functions

Methods

first

(
  • xs
)
Any | Null

Given a array, string or otherwise sequencial object, returns the first item

Parameters:

  • xs String | Array | Array-like

    Sequencial object

Returns:

Any | Null:

First item or null

Example:

import {first} from './utils/array';

first([1, 2, 3, 4]); // -> 1

flatten

(
  • xs
)
Array

If given a multidimensional array, flattens it into a single dimension and returns the result

Parameters:

  • xs Array

    Multidimensional array

Returns:

Array:

Flattened array

Example:

import {flatten} from './utils/array';

flatten([1, 2, [3, [4]]]);
// -> [1, 2, 3, 4]

head

(
  • xs
)
Array

Given a array, string or otherwise sequencial object, returns the head item

Parameters:

  • xs String | Array | Array-like

    Sequencial object

Returns:

Array:

List with the head item

Example:

import {head} from './utils/array';

head([1, 2, 3, 4]);
// -> [1]

initial

(
  • xs
)
Array

Given a array, string or otherwise sequencial object, returns all items but the last

Parameters:

  • xs String | Array | Array-like

    Sequencial object

Returns:

Array:

List with the initial items

Example:

import {initial} from './utils/array';

initial([1, 2, 3, 4]);
// -> [1, 2, 3]

last

(
  • xs
)
Any | Null

Given a array, string or otherwise sequencial object, returns the last item

Parameters:

  • xs String | Array | Array-like

    Sequencial object

Returns:

Any | Null:

Last item or null

Example:

import {last} from './utils/array';

last([1, 2, 3, 4]);
// -> 4

rest

(
  • xs
)
Array

Given a array, string or otherwise sequencial object, returns all items but the first

Parameters:

  • xs String | Array | Array-like

    Sequencial object

Returns:

Array:

List with the rest items

Example:

import {rest} from './utils/array';

rest([1, 2, 3, 4]);
// -> [2, 3, 4]

sizeOf

(
  • xs
)
Number

Given a enumerable value, counts the number of items the enumerable contains

Parameters:

  • xs String | Array | Array-like | Object

    Enumerable

Returns:

Number:

Number of items inside xs

Example:

import {sizeOf} from './utils/array';

sizeOf('hello world'); // -> 11
sizeOf([1, 2, 3]); // -> 3
sizeOf({a: 1, b: 2, c: 3}); // -> 3

tail

(
  • xs
)
Array

Given a array, string or otherwise sequencial object, returns the tail item

Parameters:

  • xs String | Array | Array-like

    Sequencial object

Returns:

Array:

List with the tail item

Example:

import {tail} from './utils/array';

tail([1, 2, 3, 4]);
// -> [4]

toArray

(
  • v
)
Array

Converts strings, objects and array-like values into real arrays.

Parameters:

  • v String | Array-like | Object

    Value to transform

Returns:

Array:

A real array

Example:

import {toArray} from './utils/array';

var nodes = toArray(document.querySelectorAll('div'));
// -> [<div>, <div>, ...]