From e882b94cf671f4c2eb8920a22e0213bbbb1754a5 Mon Sep 17 00:00:00 2001 From: Mike Caputo Date: Sun, 15 Nov 2020 12:22:52 -0800 Subject: [PATCH 1/2] Change variable name to not conflict with GM YYC compiler. Also fix spelling of one variable. --- scripts/GMLodash/GMLodash.gml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/GMLodash/GMLodash.gml b/scripts/GMLodash/GMLodash.gml index bebfeae..89bff7f 100644 --- a/scripts/GMLodash/GMLodash.gml +++ b/scripts/GMLodash/GMLodash.gml @@ -671,19 +671,19 @@ function GMLodash() constructor { return result; }; - static join = function join(collection, seperator) { + static join = function join(collection, separator) { var adapter = get_adapter_for(collection); var result = ""; - seperator = seperator == undefined ? "," : seperator; + separator = separator == undefined ? "," : separator; var stack = ds_stack_create(); for (var i = 0, isize = adapter.size(collection); i < isize; ++i) { var value = adapter.get(collection, i); ds_stack_push(stack, [value, isize - 1]); while(!ds_stack_empty(stack)) { - var args = ds_stack_pop(stack); - value = args[0]; - var limit = args[1]; + var arguments = ds_stack_pop(stack); + value = arguments[0]; + var limit = arguments[1]; if (is_collection(value)) { var jadapter = get_adapter_for(value); @@ -695,7 +695,7 @@ function GMLodash() constructor { else { result += string(value); if (i < limit) - result += seperator; + result += separator; } } } From 798c929ca96449d60db1a1d32c5ea4895e673a1e Mon Sep 17 00:00:00 2001 From: Mike Caputo Date: Sun, 28 Nov 2021 08:18:02 -0500 Subject: [PATCH 2/2] Adds boolean check to isequal function. Also adds two other functions. --- scripts/GMLodash/GMLodash.gml | 42 ++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/scripts/GMLodash/GMLodash.gml b/scripts/GMLodash/GMLodash.gml index 89bff7f..5b90259 100644 --- a/scripts/GMLodash/GMLodash.gml +++ b/scripts/GMLodash/GMLodash.gml @@ -1,3 +1,11 @@ +// Project: +// https://github.com/DatZach/GMLodash + +// Documentation: +// https://github.com/DatZach/GMLodash/wiki/Collections +// https://github.com/DatZach/GMLodash/wiki/Language +// https://github.com/DatZach/GMLodash/wiki/Utility + #macro _ gmLodashInstance() function GMLodash() constructor { @@ -242,7 +250,34 @@ function GMLodash() constructor { return false; }; - + + // For simple array-checking, this is more performant than the `includes` function. + static flatArrayIncludes = function flatArrayIncludes(array, value) { + for(var i = 0; i < array_length(array); i++) { + if(array[i] == value) { + return true; + } + } + return false; + }; + + // Returns the index of an item within a collection. + static indexOf = function indexOf(collection, iteratee) { + var adapter = get_adapter_for(collection); + var keys = adapter.keys(collection); + iteratee = get_iteratee(iteratee); + + for (var i = 0, isize = adapter.size(collection); i < isize; ++i) { + var key = adapter.isMap ? keys[i] : i; + var value = adapter.get(collection, key); + if(iteratee(value, key, collection)) { + return i; + } + } + + return undefined; + }; + static keyBy = function keyBy(collection, iteratee) { var cadapter = get_adapter_for(collection); var radapter = get_map_adapter_for(collection); @@ -516,6 +551,8 @@ function GMLodash() constructor { } else if (is_ptr(a) && is_ptr(b)) return a == b; + else if (is_bool(a) && is_bool(b)) + return a == b; // TODO More types? @@ -699,7 +736,6 @@ function GMLodash() constructor { } } } - ds_stack_destroy(stack); return result; }; @@ -952,4 +988,4 @@ function gmlodash_ds_exists(index, type) { function gmLodashInstance() { static instance = new GMLodash(); return instance; -} \ No newline at end of file +}