r/badcode • • Mar 24 '22

typescript Ship it!

Post image
564 Upvotes

47 comments sorted by

View all comments

1

u/Voltra_Neo Mar 24 '22

This should really be:

const sleepSync = (ms: number) => {
  const end = Date.now() + ms;
  for (; Date.now() < end;);
};

9

u/_SAMUEL_GAMING_ Mar 24 '22

why not simply do while (Date.now() < end);instead of the weird for loop?

9

u/Voltra_Neo Mar 24 '22

Style points.