Skip to content

diff

Create an array of differences between two arrays

209 bytes
since v12.1.0

Usage

Given two arrays, returns an array of all items that exist in the first array but do not exist in the second array.

import * as
import _
_
from 'radashi'
const
const oldWorldGods: string[]
oldWorldGods
= ['ra', 'zeus']
const
const newWorldGods: string[]
newWorldGods
= ['vishnu', 'zeus']
const
const diff: string[]
diff
=
import _
_
.
function diff<string>(root: readonly string[], other: readonly string[], identity?: (item: string) => string | number | symbol): string[]

Returns all items from the first list that do not exist in the second list.

@seehttps://radashi.js.org/reference/array/diff

@example

diff([1, 2, 3, 4], [2, 4])
// [1, 3]
diff([{a:1}, {a:2}, {a:3}], [{a:2}, {a:4}], (n) => n.a)
// [{a:1}, {a:3}]

@version12.1.0

diff
(
const oldWorldGods: string[]
oldWorldGods
,
const newWorldGods: string[]
newWorldGods
) // => ['ra']