Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mrijk committed Jul 18, 2018
1 parent 9b03b28 commit 45c9ea3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions examples/setgame.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// of https://gist.github.com/cgrand/4985a7ef80c8c85291213437d06d9169
// by Christophe Grand

const _ = require('lodash');
const {flow, head, map, size, uniq} = require('lodash');
const debug = require('debug')('setgame');

const gen = require('../lib/gen');
const s = require('../lib/spec');
Expand All @@ -16,7 +17,7 @@ s.def('::card', s.keys({req: ['::shape', '::color', '::value', '::shading']}));
s.def('::deck', s.collOf('::card', {distinct: true, maxCount: 12, minCount: 12}));

function uniqueOrDistinct(feature) {
return x => _(x).map(feature).uniq().size() !== 2;
return x => flow(map(feature), uniq, size)(x) !== 2;
}

s.def('::set',
Expand All @@ -28,7 +29,7 @@ s.def('::set',
uniqueOrDistinct('::shading')));

function deal() {
return _.head([...gen.sample(s.gen('::deck'), 1)]);
return head([...gen.sample(s.gen('::deck'), 1)]);
}

function* sets(deck) {
Expand All @@ -43,4 +44,4 @@ function* sets(deck) {
}
}

console.log([...sets(deal())]);
debug([...sets(deal())]);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"license": "MIT",
"dependencies": {
"debug": "^3.1.0",
"lodash": "^4.17.10",
"testcheck": "^1.0.0-rc.2"
},
Expand All @@ -45,7 +46,7 @@
"eslint": "^5.1.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-lodash": "^2.7.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-node": "^7.0.1",
"genfun": "^5.0.0",
"gh-pages": "^1.2.0",
"gitbook-cli": "^2.3.2",
Expand Down

0 comments on commit 45c9ea3

Please sign in to comment.