Sequence NODE_226
Easy

Create a Countdown Timer Script

Node.js
Technical Specification

Create a CLI script that counts down from N seconds to 0 and logs each second.

Input/Output Samples
Input:node timer.js 5
Output:5 4 3 2 1 0
Optimal Logic Path
let seconds = Number(process.argv[2] || 5);
const id = setInterval(() => {
  console.log(seconds);
  if (seconds-- <= 0) clearInterval(id);
}, 1000);
Architectural Deep-Dive
We schedule a repeated function every second and stop when the counter hits zero.