aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/search.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/examples/search.js b/examples/search.js
index b35c9b8..7a64042 100644
--- a/examples/search.js
+++ b/examples/search.js
@@ -32,7 +32,7 @@ function Search(searchBlock){ // searchBlock should be a Space object.
this.add = function(loc, space){ // loc should be [tileY,tileX] and space Space.
this.tiles[loc] = space;
let inds = Array(2); // Records horizontal and vertical indices for insertion. Then actually inserts the item.
- [null,null].forEach( (item, ind) => {
+ [0,1].forEach( ind => { // ind chooses y-or-x
inds[ind] = -bs(this.sort[ind], loc, getComp(ind))-1;
if (inds[ind] < 0) throw "loc should not be a part of the list";
this.sort[ind].splice(inds[ind], 0, loc);
@@ -49,10 +49,11 @@ function Search(searchBlock){ // searchBlock should be a Space object.
//return searchspace.search(searchBlock); // According to space docs, [] on failure and a character location on success
}
- this.block = function(loc,inds,exclude=new Set()){
+ this.block = function(loc,inds,exclude){
+ if (! exclude) exclude = new Set(); // If not given, replace.
let adjacent = new Set([loc]);
exclude.add(loc);
- [null,null].forEach( (item, ind) => {
+ [0,1].forEach( ind => {
// inds[ind] is address, so check neighbors on sort[ind] (up, then down)
// until sort[ind][inds[ind]][ind] != sort[ind][otherind][ind].
// on each, if sort[ind][otherind][1-ind] == sort[ind][inds[ind]][1-ind],
@@ -68,7 +69,7 @@ function Search(searchBlock){ // searchBlock should be a Space object.
this.del = function(loc){
delete this.tiles[loc];
- [null,null].forEach( (item,ind) => {
+ [0, 1].forEach( ind => {
let theind = bs(this.sort[ind], loc, getComp(ind));
if (theind < 0) throw "loc must already be a part of the list";
this.sort[ind].splice(bs(this.sort[ind], loc, getComp(ind)), 1);