Spinner While Waiting

Spinner While Waiting

Hard NodeJS CLI Tools & Debugging 24 views
Explanation Complexity

Problem Statement

Show a simple spinner for 1 second then print DONE.

Input Format

No input.

Output Format

Print animation then DONE.

Constraints

Use setInterval and clearInterval.

Input / Output Format

Input Format
No input.
Output Format
Print animation then DONE.
Constraints
Use setInterval and clearInterval.

Example Solution (Public)

NodeJS
const frames = ['|', '/', '-', '\\\\'];
let i = 0;
process.stdout.write('meetcode ');
const id = setInterval(() => {
  process.stdout.write('\
meetcode ' + frames[i % frames.length]);
  i += 1;
}, 80);
setTimeout(() => {
  clearInterval(id);
  process.stdout.write('\
meetcode DONE\
');
}, 1000);

Official Solution Code

const frames = ['|', '/', '-', '\\\\'];
let i = 0;
process.stdout.write('meetcode ');
const id = setInterval(() => {
  process.stdout.write('\
meetcode ' + frames[i % frames.length]);
  i += 1;
}, 80);
setTimeout(() => {
  clearInterval(id);
  process.stdout.write('\
meetcode DONE\
');
}, 1000);
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.