• @[email protected]
    link
    fedilink
    English
    68
    edit-2
    1 year ago

    Wow. Amateur hour over here. There’s a much easier way to write this.

    A case select:

    select(number){
        case 1:
            return false;
        case 2:
            return true;
    }
    

    And so on.

    • robotica
      link
      fedilink
      13
      edit-2
      1 year ago

      Don’t forget that you can have fall-through cases, so you can simplify it even further:

      switch (number) {
          case 1:
          case 3:
          case 5:
          case 7:
          case 9:
            ...