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
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 PlaygroundThe original vector stays as it was.
block(v:[1],w:append(v,2),[v,w])
// → [[1], [1, 2]]Open in PlaygroundBuild 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 PlaygroundGood to know
- The first argument must be a vector:
append({1,2},3)is an error. To add to a set, useunion.
JavaScript examples
nerdamer.append('[1,2]', '3').text()
// → [1, 2, 3]