This is immediate, through the use of a TrueSet
representing each item with the position the item is expected to assume.
const
repr = item => item==='role'? 0: 1,
got = TrueSet.of(repr, ORDER.ASCENDING, ORDER.INSERTION)
.letAll(data)
.toArray();
The role
item is expected to occupy position 0
, while the other items are expected to occupy position 1
. The positions are arranged in ascending order. All items sharing the same position maintain their order of insertion. The role
item may or may not be present in the array.
You can check the validity of the proposed solution by:
import {TrueSet} from "@ut8pia/classifier/queue/TrueSet.js";
import {ORDER} from "@ut8pia/classifier/global.js";
import assert from "assert";
const
data = ["email","role","type","name"],
expected = ["role","email","type","name"];
assert.deepEqual(got, expected)
If you are unfamiliar with TrueSet
and the representation
function, exploring the @ut8pia/classifier library's online documentation could be helpful.
remove
method? Are you using Prototype.js or something similar?if('role' in data)
anddata.remove()
?