client side data models

This commit is contained in:
Eric Hulburd
2016-02-09 19:17:05 -06:00
parent a334afbc01
commit b14c266de3
12 changed files with 298 additions and 1 deletions

30
shared/utils/array.js Normal file
View File

@@ -0,0 +1,30 @@
class ArrayUtil {
static diff(a1, a2){
a1.filter((a1n)=>{ return a2.indexOf(a1n) < 0; });
}
static selectMap(a, fnSelect, fnMap){
var map = [];
for (var elem of a){
if (fnSelect(elem)){
map.push(fnMap(elem));
}
}
return map;
}
static all(a, fnCondition){
var all = true;
for (var elem of a){
if (!fnCondition(elem)){
all = false;
break;
}
}
return all;
}
}
export default ArrayUtil;

View File

@@ -7,4 +7,26 @@ export default class {
static n6(){
return ((Math.random() + Math.random() + Math.random() + Math.random() + Math.random() + Math.random()) - 3) / 3;
}
// min_max1 and min_max2 arrays of length two representing mins and maxes of their ranges;
// returns array of array length two, representing mins and maxes not within min_max2.
static minusRange(min_max1, min_max2){
var minus = [];
if (min_max1[0] >= min_max2[0]){
if (min_max1[1] > min_max2[1]) minus.push([min_max2[1], min_max1[1]]);
} else if (min_max1[1] <= min_max2[1]){
if (min_max1[0] < min_max2[0]) minus.push([min_max1[0], min_max2[0]]);
} else if (min_max1[0] < min_max2[0] && min_max1[1] > min_max2[1]){
minus.push([min_max1[0], min_max2[0]]);
minus.push([min_max2[1], min_max1[1]]);
} else {
minus.push([min_max1[0], min_max1[1]]);
}
return minus;
}
static inRange(n, min_max){
return n >= min_max[0] && n =< min_max[1];
}
}