Skip to content

Instantly share code, notes, and snippets.

@goldensunliu
Last active March 5, 2018 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldensunliu/fb54f6a2972883a3a61e9b942517a7b5 to your computer and use it in GitHub Desktop.
Save goldensunliu/fb54f6a2972883a3a61e9b942517a7b5 to your computer and use it in GitHub Desktop.
function getNumberOfGroupsAssignedForNumber(number, groups) {
return groups.reduce((accumulator, row) =>
accumulator + (row.get(number) > 0 ? 1 : 0), 0);
}
class Game extends Compoent {
...
// get the min between its completion in rows, columns and squares.
getNumberValueCount(number) {
const rows = this.state.board.getIn(['choices', 'rows']);
const columns = this.state.board.getIn(['choices', 'columns']);
const squares = this.state.board.getIn(['choices', 'squares']);
return Math.min(
getNumberOfGroupsAssignedForNumber(number, squares),
Math.min(
getNumberOfGroupsAssignedForNumber(number, rows),
getNumberOfGroupsAssignedForNumber(number, columns),
),
);
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment