Created
May 26, 2020 13:08
-
-
Save galElmalah/1a659b2fd9981116360215305cfa3d71 to your computer and use it in GitHub Desktop.
actions map
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
const ACTIONS = { | |
SORT: "SORT", | |
COMPARE: "COMPARE", | |
SWAP: "SWAP", | |
}; | |
// ---- what to do on each action ---- | |
const actionsMap = { | |
[ACTIONS.SORT]: (action, members) => members[action.data].sorted(), | |
[ACTIONS.SWAP]: (action, members) => { | |
const [i, j] = action.data; | |
let tmp = members[i].getValue(); | |
members[i].setValue(members[j].getValue(), "red"); | |
members[j].setValue(tmp, "yellow"); | |
}, | |
[ACTIONS.COMPARE]: (action, members) => { | |
const [i, j] = action.data; | |
members[i].setColor("blue"); | |
members[j].setColor("blue"); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment