1 |
const repeat = (func, times) => [...Array(times).keys()].map(func); |
1 2 3 4 5 6 7 8 9 10 |
const countingRhyme = n => {console.log(`${10 - n * 2 } fat Sausages sizzling in a pan${10 - n * 2 && ' one went pop and the other went bang' || ''}!`); return n}; repeat(countingRhyme, 6); // => 10 fat Sausages sizzling in a pan one went pop and the other went bang! // => 8 fat Sausages sizzling in a pan one went pop and the other went bang! // => 6 fat Sausages sizzling in a pan one went pop and the other went bang! // => 4 fat Sausages sizzling in a pan one went pop and the other went bang! // => 2 fat Sausages sizzling in a pan one went pop and the other went bang! // => 0 fat Sausages sizzling in a pan! |