([opponent,you])=>// part 1: each Round has [Shape, Shape]
[
// outcome points index: 0: Lose, 1: Draw, 2: Win
(1+2*opponent+you)%3,
// you points index: 0: Rock, 1: Paper, 2: Scissors
you,
],
// :: Round → Outcome
([opponent,outcome])=>[// part 2: each Round has [Shape, Outcome]
// 0: Lose, 1: Draw, 2: Win
outcome,
// shape you must play to achieve given outcome
(opponent+outcome+2)%3,// 0: Rock, 1: Paper, 2: Scissors
]
]
// normalize :: Token → Round
// convert a letter tuple to its number tuple
// ["A", "Y"] → [0, 1]
normalize=([p,q])=>([A(p),X(q)])
normalize(["A","Y"])
// score :: Outcome → Score
// takes an Outcome
// returns its Score
score=([outcome,you])=>[
[0,3,6][outcome],// Lose, Draw, Win
[1,2,3][you]// Rock, Paper, Scissors
]
score([2,1])
// takes character
// returns distance from "A"
A=n("A")
#### ƒ `X :: Letter → Number`
// takes character
// returns distance from "X"
X=n("X")
// takes a base character
// returns function that takes a character and returns its distance from base
n=(base)=>(c)=>c.charCodeAt(0)-base.charCodeAt(0)
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.