Comment

Comment by bananaface

Why not just:

    function foobar(version: number): string {
      if      (version >= 3) { return 'result_3'; }
      else if (version >= 2) { return 'result_2'; }
      else if (version >= 1) { return 'result_1'; }
      else {
        throw new Error(`Cannot interpret version '${version}'`);
      }
    }
?

I don't see what advantage the switch provides here.

parent bananaface 5 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton