UNPKG

@nodescript/stdlib

Version:
42 lines (41 loc) 1.03 kB
export const module = { version: '1.1.4', moduleName: 'Array / Filter', description: ` Returns items of specified array for which the corresponding condition is true. The array and conditions are expected to correspond to each other by index. `, keywords: ['find', 'match'], params: { array: { schema: { type: 'array', items: { type: 'any' }, }, hideEntries: true, }, conditions: { schema: { type: 'array', items: { type: 'boolean' }, }, hideEntries: true, }, }, result: { schema: { type: 'array', items: { type: 'any' }, }, }, }; export const compute = params => { const { array, conditions } = params; const res = []; for (const [i, item] of array.entries()) { if (conditions[i]) { res.push(item); } } return res; };