@nodescript/stdlib
Version:
Standard Node Definitions
34 lines (33 loc) • 728 B
JavaScript
export const module = {
version: '1.1.4',
moduleName: 'Array / Repeat',
description: `
Constructs an array of given length filled with specified item.
`,
keywords: ['fill'],
params: {
item: {
schema: { type: 'any' },
},
length: {
schema: {
type: 'number',
default: 1,
},
},
},
result: {
schema: {
type: 'array',
items: { type: 'any' },
}
},
};
export const compute = params => {
const { item, length } = params;
const array = new Array(length);
for (let i = 0; i < length; i++) {
array[i] = item;
}
return array;
};