diff options
-rw-r--r-- | space.js | 10 | ||||
-rw-r--r-- | tests/space_subsection.js | 10 |
2 files changed, 18 insertions, 2 deletions
@@ -110,9 +110,15 @@ function Space(){ // CLASS } this.subsection = function(range){ // range is a standard quadruplet newspace = new Space(); - for (let line=0; line<range[2]-range[0]; line++) for (let chr=0; chr<range[3]-range[1]; chr++){ - newspace.data[line][chr] = this.data[line+range[0]][line+range[1]] || ''; + for (let line=0; line<=range[2]-range[0]; line++){ + newspace.data.push([]); + for (let chr=0; chr<=range[3]-range[1]; chr++){ + newspace.data[line].push( + this.data[line+range[0]][chr+range[1]] || '' + ); + } } + return newspace; } } diff --git a/tests/space_subsection.js b/tests/space_subsection.js new file mode 100644 index 0000000..a2523e5 --- /dev/null +++ b/tests/space_subsection.js @@ -0,0 +1,10 @@ +// Tests Space.subsection() +const space = require('../space'); + +newspace = new space.Space(); +newspace.adhoc('\ +line\n\ +\n\ +long long long line\ +'); +console.log(newspace.subsection([1,1,2,10])); |