UNPKG

@nodescript/stdlib

Version:
54 lines (53 loc) 1.34 kB
export const module = { version: '1.0.2', moduleName: 'Array / Bisect', description: ` Splits the array into "positive" and "negative" subarrays, based on the per-element condition. The array and conditions are expected to correspond to each other by index. `, keywords: ['find', 'filter', 'match'], params: { array: { schema: { type: 'array', items: { type: 'any' }, }, hideEntries: true, }, conditions: { schema: { type: 'array', items: { type: 'boolean' }, }, hideEntries: true, }, }, result: { schema: { type: 'object', properties: { positive: { type: 'any', }, negative: { type: 'any', }, } }, }, }; export const compute = params => { const { array, conditions } = params; const positive = []; const negative = []; for (const [i, item] of array.entries()) { if (conditions[i]) { positive.push(item); } else { negative.push(item); } } return { positive, negative }; };