Last updated 4 years ago
Was this helpful?
check invalid input
if boolean type return 'TypeError'
if is not integer return 'TypeError'
if is less than 0 return 'TypeError'
repeat *n times 'a' character and split as an array (it's for iteration)
iterate and return *v
const prefill = (n, v) => { if (typeof n === 'boolean' || !Number.isInteger(Number(n)) || Number(n) < 0) { throw new TypeError(`${n} is invalid`); } return [...'a'.repeat(Number(n))].map(() => v); };