Transition to using UnitJS's fun module
This commit is contained in:
parent
555e4386e3
commit
bfb86a6a0d
4 changed files with 2 additions and 67 deletions
64
www/fun.js
64
www/fun.js
|
@ -1,64 +0,0 @@
|
|||
function Fun() {
|
||||
return {
|
||||
defaultCompare: defaultCompare,
|
||||
insert: insert,
|
||||
map: map,
|
||||
mapFilter: mapFilter,
|
||||
isSet: isSet,
|
||||
of: of,
|
||||
proj: proj
|
||||
};
|
||||
|
||||
function insert(obj, t, compare, min, max) {
|
||||
min = min == undefined ? 0 : min;
|
||||
max = max == undefined ? t.length : max;
|
||||
compare = compare == undefined ? defaultCompare : compare;
|
||||
if(max - min < 1) {
|
||||
return min;
|
||||
}
|
||||
var avg = Math.floor((max + min) / 2);
|
||||
if (compare(obj, t[avg]) < 0) {
|
||||
return insert(obj, t, compare, min, avg);
|
||||
} else {
|
||||
return insert(obj, t, compare, avg+1, max);
|
||||
}
|
||||
}
|
||||
|
||||
function defaultCompare(a, b) {
|
||||
if(a < b) {
|
||||
return -1;
|
||||
} else if(a > b) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function map(mapper, f) {
|
||||
return function() {
|
||||
var args = Array.prototype.map.call(arguments, mapper);
|
||||
return f.apply(null, args);
|
||||
}
|
||||
}
|
||||
|
||||
function of(o) {
|
||||
return function(key) {return o[key];};
|
||||
}
|
||||
|
||||
function proj(key) {
|
||||
return function(o) {return o[key];};
|
||||
}
|
||||
|
||||
function mapFilter(mapper, predicate) {
|
||||
return function(array) {
|
||||
return array.reduce(function(accumulator, elem) {
|
||||
var v = mapper(elem);
|
||||
return predicate(v) ? accumulator.concat(v) : accumulator;
|
||||
}, []);
|
||||
};
|
||||
}
|
||||
|
||||
function isSet(x) {
|
||||
return x != undefined;
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@
|
|||
<script src="lib/unit.js"></script>
|
||||
<script src="translations.js"></script>
|
||||
<script src="i18n.js"></script>
|
||||
<script src="fun.js"></script>
|
||||
<script src="screen.js"></script>
|
||||
<script src="save.js"></script>
|
||||
<script src="messaging.js"></script>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
window.addEventListener('load', function() {
|
||||
var dom = unitJS.Dom();
|
||||
var async = unitJS.Async();
|
||||
var fun = unitJS.Fun();
|
||||
var translations = Translations();
|
||||
var i18n = I18n({translations: translations});
|
||||
var fun = Fun();
|
||||
var save = Save();
|
||||
var screen = Screen({dom: dom, i18n: i18n});
|
||||
var messaging = Messaging({screen: screen});
|
||||
|
|
|
@ -242,7 +242,7 @@ Screen.Game = function(modules) {
|
|||
function matchingInRiver(card) {
|
||||
return modules.fun.mapFilter(
|
||||
modules.fun.of(sets.river.card),
|
||||
modules.fun.isSet
|
||||
modules.fun.defined
|
||||
)(modules.hanafuda.sameMonth(card).map(modules.fun.proj('name')));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue