• @[email protected]
    link
    fedilink
    English
    68
    edit-2
    8 months 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
      8 months 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:
            ...