Last active
January 5, 2020 15:55
-
-
Save horiuchie/a3cda36c7ff68ebbf7f8bd2b76eedd46 to your computer and use it in GitHub Desktop.
incomplete "pattern matching" in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as R from 'ramda'; | |
const condition = R.unapply(R.toString); | |
const sameAs = condition; | |
function viewMode (orientation, layoutNo) { | |
switch (condition(orientation, layoutNo)) { | |
case sameAs('portrait', 2): | |
return 'video and description'; | |
case sameAs('landscape', 1): | |
case sameAs('landscape', 2): | |
return 'video only'; | |
default: | |
return 'video and description and messages'; | |
} | |
} | |
viewMode('portrait', 1); | |
// => video and description and messages | |
viewMode('portrait', 2); | |
// => video and description | |
viewMode('landscape', 2); | |
// => video only | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment