Split consumes a subject which is an array¹ or plain object², and a visitor function. The visitor is called for each item in the subject, with the signature (value, index, host)¹ or ([key, value], index, hostEntries)², and should return an integer indicating a group the item belongs to; Split returns an array whose contents are the groups consisting of the items for which the visitor returned that index, each group being of the same type as the subject (array or plain object).
Eg:
const [odd, even] = split(
[9, 4, 6, 7, 2, 3],
x => x % 2 ? 0 : 1,
)
// odd == [4, 6, 2]
// even == [9, 7, 3]
const [events, other] = split(
{
onclick : () => {},
onchange : () => {},
config : {},
initial : true,
},
// 👇 Signature exposes [key, value] as first argument
([key]) => key.startsWith('on') ? 0 : 1,
)
// events == {onclick, onchange}
// other == {config, initial}