Policies & Guidelines

WITH_UNIQUE_ITEM

Add unique item to the array

Description

Returns a new array which contains the given item at the end of the array, but only if the exact item does not already exist in the array. If it does, the original array is returned.

Function signature

WITH_UNIQUE_ITEM(array: Array, item: ) => Array

Parameter

Description

Array

Array to add item to

Item

Item to add

Examples

numbers = [100,3,20]
animals = ["cat","dog"]
empty = []

Formula

Return value

WITH_UNIQUE_ITEM(numbers, 4)

[100,3,20,4]

WITH_UNIQUE_ITEM(numbers, 3)

[100,3,20]

WITH_UNIQUE_ITEM(animals, "pig")

["cat","dog","pig"]

WITH_UNIQUE_ITEM(empty, 4)

[4]