Skip to content

Commit

Permalink
Document _toArray, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
twisterghost committed Feb 4, 2017
1 parent 08325b5 commit d2a812b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ gdash is a functional utility library for GML, inspired by [lodash](https://loda
* [`_split(string, splitter)`](#_splitstring-splitter)
* [`_spread(script, argArray)`](#_spreadscript-argarray)
* [`_times(script)`](#_timesscript)
* [`_toArray(list)`](#_toarraylist)
* [`_typeOf(value)`](#_typeofvalue)
* [`_uniq(array)`](#_uniqarray)

Expand Down Expand Up @@ -542,6 +543,16 @@ _times(3, returnTheValue5);
// => [5, 5, 5];
```

### `_toArray(list)`

Returns the given ds_list as an array

```
@param {DS_List} the list to convert
@returns {Array} An array representation of the given list
Note: If the given list is of size 0, this will return undefined
```

### `_typeOf(value)`

Returns the variable type of the given argument
Expand Down
14 changes: 13 additions & 1 deletion src/gdash/objects/obj_gdash_test_2/Other_23.gml
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
test_suite_pass();
/// _toArray
test_start("_toArray", "Converts a list to an array");

var list = ds_list_create();
ds_list_add(1, 2, 3, 4, 5);

var arr = _toArray(list);

for (var i = 0; i < _length(arr); i++) {
assert_equal(list[| i], arr[i]);
}

test_end();
1 change: 1 addition & 0 deletions src/gdash/objects/obj_gdash_test_2/Other_24.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_suite_pass();
10 changes: 10 additions & 0 deletions src/gdash/objects/obj_gdash_test_2/obj_gdash_test_2.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/gdash/scripts/_toArray/_toArray.gml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
/// @desc Converts the given ds_list to an array
/// @param list
/// Note: If the given list is of size 0, this will return undefined.

var list = argument0;
var listSize = ds_list_size(list);
var array;
array[0] = undefined;

for (var i = listSize - 1; i >= 0; i--) {
array[i] = list[| i];
}

if (is_undefined(array[0])) {
return undefined;
}

return array;

0 comments on commit d2a812b

Please sign in to comment.