Hacker News new | ask | show | jobs
by jbob2000 2985 days ago
Instead of using if or switch statements to compute a value, you can use a prettier interface.

So this:

  function getStatus(status) {
    if (status === 200){
      return "Success";
    } else if (status === 401){
      return "Fail!";
    }
  }

  var myString = getStatus(response.status);
Now becomes this:

  var myString = match (status) {
    {200} => "Success",
    {401} => "Fail!"
  }
1 comments

More like:

  var myString = match (status) {
    200 => "Success",
    401 => "Fail!"
  }