본문으로 건너뛰기

orderedMerge

Merges two string arrays with priority-based ordering and duplicate removal. This function is used when merging object property keys in JSON schema, preserving the order of important properties defined in the schema while including additional properties.

Signature

const orderedMerge: (preferred: string[], source: string[]) => string[]

Parameters

NameTypeDescription
preferredKeys-Array of keys to be placed first (order is preserved)
keys-Array of additional keys to merge

Returns

Array of keys with duplicates removed and sorted by priority

Examples

Example 1

orderedMerge(['name', 'email'], ['id', 'name', 'phone'])
// Result: ['name', 'email', 'id', 'phone']

Playground

orderedMerge(['name', 'email'], ['id', 'name', 'phone'])
// Result: ['name', 'email', 'id', 'phone']