Skip to content

Commit

Permalink
Fix map and spread
Browse files Browse the repository at this point in the history
  • Loading branch information
twisterghost committed Sep 13, 2020
1 parent 7e17470 commit e43c704
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/gdash/scripts/_array_of/_array_of.gml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function _array_of() {
// => ['hello', 'world', 'i', 'am', 'an', 'array'];
*/

var result;
var result = [];

for (i = argument_count-1; i >= 0; i--) {
result[i] = argument[i];
Expand Down
2 changes: 1 addition & 1 deletion src/gdash/scripts/_backward/_backward.gml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function _backward(arr) {
*/

var len;
var result;
var result = [];

len = array_length(arr);

Expand Down
2 changes: 1 addition & 1 deletion src/gdash/scripts/_chunk/_chunk.gml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function _chunk(arr, size) {

var i;
var len;
var result;
var result = [];

if (size == 0) return array_create(0);

Expand Down
2 changes: 1 addition & 1 deletion src/gdash/scripts/_collect/_collect.gml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function _collect(object) {
// => [10001, 10002, 10005]
*/

var result;
var result = [];

for (var i = instance_number(object); i >= 0; i--) {
result[i] = instance_find(object, i);
Expand Down
14 changes: 7 additions & 7 deletions src/gdash/scripts/_difference/_difference.gml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ function _difference() {
var n;
var arr;
var len;
var set;
var result;
var tempSet;
var result = [];

set = ds_map_create();
tempSet = ds_map_create();

for (i = 1; i < argument_count; i++) {
arr = argument[i];
len = array_length(arr);
for (j = 0; j < len; j++) {
if (set[? arr[j]] != 1) {
set[? arr[j]] = 1;
if (tempSet[? arr[j]] != 1) {
tempSet[? arr[j]] = 1;
}
}
}
Expand All @@ -42,12 +42,12 @@ function _difference() {
result = array_create(0);

for (i = 0; i < len; i++) {
if (set[? arr[i]] != 1) {
if (tempSet[? arr[i]] != 1) {
result[n++] = arr[i];
}
}

ds_map_destroy(set);
ds_map_destroy(tempSet);
return result;


Expand Down
14 changes: 7 additions & 7 deletions src/gdash/scripts/_difference_by/_difference_by.gml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ function _difference_by() {
var crit;
var iter;
var len;
var set;
var result;
var tempSet;
var result = [];

iter = argument[argument_count - 1];
set = ds_map_create();
tempSet = ds_map_create();

for (i = 1; i < argument_count; i++) {
arr = argument[i];
len = array_length(arr);
for (j = 0; j < len; j++) {
crit = script_execute(iter, arr[j]);
if (set[? crit] != 1) {
set[? crit] = 1;
if (tempSet[? crit] != 1) {
tempSet[? crit] = 1;
}
}
}
Expand All @@ -51,12 +51,12 @@ function _difference_by() {

for (i = 0; i < len; i++) {
crit = script_execute(iter, arr[i]);
if (set[? crit] != 1) {
if (tempSet[? crit] != 1) {
result[n++] = arr[i];
}
}

ds_map_destroy(set);
ds_map_destroy(tempSet);
return result;


Expand Down
2 changes: 1 addition & 1 deletion src/gdash/scripts/_drop/_drop.gml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function _drop(arr, num) {
var i;
var n;
var len;
var result;
var result = [];

if (num == 0) return arr;

Expand Down
2 changes: 1 addition & 1 deletion src/gdash/scripts/_drop_right/_drop_right.gml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function _drop_right(arr, num) {
var i;
var n;
var len;
var result;
var result = [];

if (num == 0) return arr;

Expand Down
2 changes: 1 addition & 1 deletion src/gdash/scripts/_filter/_filter.gml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function _filter(collection, filterMethod) {
// => [0, 1]
*/

var result;
var result = [];
var j = 0;
var type = _type_of(collection);

Expand Down
16 changes: 8 additions & 8 deletions src/gdash/scripts/_intersection/_intersection.gml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ function _intersection() {
var n;
var arr;
var len;
var set;
var result;
var tempSet;
var result = [];

set = ds_map_create();
tempSet = ds_map_create();

for (i = 1; i < argument_count; i++) {
arr = argument[i];
len = array_length(arr);
for (j = 0; j < len; j++) {
if (i == 1 || set[? arr[j]] == i - 1) {
set[? arr[j]] = i;
if (i == 1 || tempSet[? arr[j]] == i - 1) {
tempSet[? arr[j]] = i;
}
}
}
Expand All @@ -45,13 +45,13 @@ function _intersection() {
result = array_create(0);

for (i = 0; i < len; i++) {
if (set[? arr[i]] == argument_count - 1) {
set[? arr[i]]++;
if (tempSet[? arr[i]] == argument_count - 1) {
tempSet[? arr[i]]++;
result[n++] = arr[i];
}
}

ds_map_destroy(set);
ds_map_destroy(tempSet);
return result;


Expand Down
16 changes: 8 additions & 8 deletions src/gdash/scripts/_intersection_by/_intersection_by.gml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ function _intersection_by() {
var crit;
var iter;
var len;
var set;
var result;
var tempSet;
var result = [];

iter = argument[argument_count - 1];
set = ds_map_create();
tempSet = ds_map_create();

for (i = 1; i < argument_count; i++) {
arr = argument[i];
len = array_length(arr);
for (j = 0; j < len; j++) {
crit = script_execute(iter, arr[j]);
if (i == 1 || set[? crit] == i - 1) {
set[? crit] = i;
if (i == 1 || tempSet[? crit] == i - 1) {
tempSet[? crit] = i;
}
}
}
Expand All @@ -49,13 +49,13 @@ function _intersection_by() {

for (i = 0; i < len; i++) {
crit = script_execute(iter, arr[i]);
if (set[? crit] == argument_count - 2) {
set[? crit]++;
if (tempSet[? crit] == argument_count - 2) {
tempSet[? crit]++;
result[n++] = arr[i];
}
}

ds_map_destroy(set);
ds_map_destroy(tempSet);
return result;


Expand Down
6 changes: 2 additions & 4 deletions src/gdash/scripts/_map/_map.gml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
function _map() {
/*
@example
var arr;
arr[0] = 1; arr[1] = 2;
_map(arr, doubleValue);
// => [2, 4];
var map = ds_map_create();
ds_map_add(map, 'hello', 6);
ds_map_add(map, 'world', 10);
Expand All @@ -23,7 +21,7 @@ function _map() {
var collection = argument[0];
var func = argument[1];
var type = "array";
var result;
var result = [];

if (argument_count == 3) {
type = argument[2];
Expand All @@ -47,4 +45,4 @@ function _map() {
}
return result;
}
}
}
2 changes: 1 addition & 1 deletion src/gdash/scripts/_slice/_slice.gml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function _slice() {
// => true
*/

var result;
var result = [];
var array = argument[0];
var starti = argument[1];
var endi = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/gdash/scripts/_split/_split.gml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function _split(inputString, splitter) {
*/

var splitterLength = string_length(splitter);
var result;
var result = [];
var splitterLocation;
var part;
var count = 0;
Expand Down
8 changes: 1 addition & 7 deletions src/gdash/scripts/_spread/_spread.gml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,4 @@ function _spread() {
case 15:
return func(args[@ 0], args[@ 1], args[@ 2], args[@ 3], args[@ 4], args[@ 5], args[@ 6], args[@ 7], args[@ 8], args[@ 9], args[@ 10], args[@ 11], args[@ 12], args[@ 13], args[@ 14]);
}






}
}
12 changes: 6 additions & 6 deletions src/gdash/scripts/_union/_union.gml
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ function _union() {
var n;
var arr;
var len;
var set;
var result;
var tempSet;
var result = [];

n = 0;
set = ds_map_create();
tempSet = ds_map_create();
result = array_create(0);

for (i = 0; i < argument_count; i++) {
arr = argument[i];
len = array_length(arr);
for (j = 0; j < len; j++) {
if (set[? arr[j]] != 1) {
set[? arr[j]] = 1;
if (tempSet[? arr[j]] != 1) {
tempSet[? arr[j]] = 1;
result[n++] = arr[j];
}
}
}

ds_map_destroy(set);
ds_map_destroy(tempSet);
return result;


Expand Down
12 changes: 6 additions & 6 deletions src/gdash/scripts/_union_by/_union_by.gml
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ function _union_by() {
var crit;
var iter;
var len;
var set;
var result;
var tempSet;
var result = [];

n = 0;
iter = argument[argument_count - 1];
set = ds_map_create();
tempSet = ds_map_create();
result = array_create(0);

for (i = 0; i < argument_count; i++) {
arr = argument[i];
len = array_length(arr);
for (j = 0; j < len; j++) {
crit = script_execute(iter, arr[j]);
if (set[? crit] != 1) {
set[? crit] = 1;
if (tempSet[? crit] != 1) {
tempSet[? crit] = 1;
result[n++] = arr[j];
}
}
}

ds_map_destroy(set);
ds_map_destroy(tempSet);
return result;


Expand Down
2 changes: 1 addition & 1 deletion src/gdash/scripts/_unzip/_unzip.gml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function _unzip(arr) {
var j;
var len;
var num;
var result;
var result = [];

len = array_length(arr);
num = array_length(arr[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/gdash/scripts/_without/_without.gml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function _without() {
var arr;
var match;
var len;
var result;
var result = [];

n = 0;
arr = argument[0];
Expand Down
2 changes: 1 addition & 1 deletion src/gdash/scripts/_zip/_zip.gml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function _zip() {
var j;
var arr;
var len;
var result;
var result = [];

len = array_length(argument[0]);
for (i = 1; i < argument_count; i++)
Expand Down

0 comments on commit e43c704

Please sign in to comment.