UNPKG

@nodescript/stdlib

Version:
32 lines (31 loc) 717 B
export const module = { version: '1.1.4', moduleName: 'Math / Sum', description: ` Computes a sum of specified items. Each item can either be a number or an array of numbers. Non-numbers are ignored. `, keywords: ['plus', 'add'], params: { items: { schema: { type: 'array', items: { type: 'any' }, }, }, }, result: { schema: { type: 'number' }, } }; export const compute = params => { let result = 0; for (const item of params.items.flat()) { const num = Number(item); if (!isNaN(num)) { result += num; } } return result; };