Skip to content

Instantly share code, notes, and snippets.

@galElmalah
Created May 26, 2020 13:08
Show Gist options
  • Save galElmalah/1a659b2fd9981116360215305cfa3d71 to your computer and use it in GitHub Desktop.
Save galElmalah/1a659b2fd9981116360215305cfa3d71 to your computer and use it in GitHub Desktop.
actions map
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