Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coffeescript refactoring

Tags:

coffeescript

Is there any coffeescript specific trickery that would make this look neater:

index = (->
          if segment == 'index'
            return 0
          else if segment == 'inbox'
            return 2

          1
        )()
like image 402
dagda1 Avatar asked Apr 27 '26 20:04

dagda1


1 Answers

Yes, a switch expression:

index = switch segment
  when 'index' then 0
  when 'inbox' then 2
  else 1
like image 191
epidemian Avatar answered Apr 30 '26 22:04

epidemian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!