Function reference · Math

append

Returns a vector with one more element at the end.

Notation

append(vector, element)

Write it in an expression: nerdamer('append([1,2],3)'), or in the Playground.

nerdamer.append

nerdamer.append(...args: [x, value]): ParserEntity

A method on the default import. Arguments can be strings, as in Notation.

import { append }

import { append } from 'nerdamer/structures';
append(vector: ParserEntity, element: ParserEntity): ParserEntity

Import only this function, from nerdamer/structures.

Parameters

vector
The vector to add to. It isn't changed.
element
The element to add. A vector is added as one element.

Returns

A new vector, one element longer.

Examples

Add a number at the end.

append([1,2],3)
// → [1, 2, 3]
Open in Playground

A vector is added as one element, so this is a vector of two vectors.

append([[1,2]],[3,4])
// → [[1, 2], [3, 4]]
Open in Playground

The original vector stays as it was.

block(v:[1],w:append(v,2),[v,w])
// → [[1], [1, 2]]
Open in Playground

Build a list in a loop, starting from the empty vector [].

block(s:[],each([3,1,2],x,s:append(s,x^2)),s)
// → [9, 1, 4]
Open in Playground

If v has no value yet, the call is kept as it is.

append(v,3)
// → append(v, 3)
Open in Playground

Good to know

  • The first argument must be a vector: append({1,2},3) is an error. To add to a set, use union.

JavaScript examples

nerdamer.append('[1,2]', '3').text()
// → [1, 2, 3]

← Back to Function reference