DEV Community

Discussion on: JavaScript Katas: Count sheep

Collapse
 
kosich profile image
Kostia Palchyk • Edited

Nice new kata, Michael!

[...Array(amountOfSheep)] — nowadays, I tend to use Array(amountOfSheep).fill(null) for such cases:
Theoretically it should be faster/smaller (while the ... looks definitely cooler!)
But I haven't checked that 😊

Also, a hacky approach 😎:

i=1, 'N sheep...,'.repeat(amountOfSheep).replace(/N/g, () => i++).replace(/,$/,'');
Collapse
 
miku86 profile image
miku86

Hey Kostia,

nice solution!

First I used the fill one, but I thought it would be interesting for beginners to read about the widely-used spread operator and see it in action.