2022-09-27 06:37:28 +02:00
|
|
|
function array_safe_get(arr, index, def = 0) {
|
|
|
|
if(index >= array_length(arr)) return def;
|
2022-01-13 05:24:03 +01:00
|
|
|
return arr[index];
|
2022-09-27 06:37:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function array_exists(arr, val) {
|
|
|
|
for( var i = 0; i < array_length(arr); i++ ) {
|
|
|
|
if(arr[i] == val) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function array_find(arr, val) {
|
|
|
|
for( var i = 0; i < array_length(arr); i++ ) {
|
|
|
|
if(arr[i] == val) return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function array_remove(arr, val) {
|
|
|
|
if(!array_exists(arr, val)) return;
|
|
|
|
var ind = array_find(arr, val);
|
|
|
|
array_delete(arr, ind, 1);
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function array_push_unique(arr, val) {
|
|
|
|
if(array_exists(arr, val)) return;
|
|
|
|
array_push(arr, val);
|
2022-12-13 14:11:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function array_append(arr, arr0) {
|
|
|
|
for( var i = 0; i < array_length(arr0); i++ )
|
|
|
|
array_push(arr, arr0[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function array_merge() {
|
|
|
|
var arr = [];
|
|
|
|
for( var i = 0; i < argument_count; i++ ) {
|
|
|
|
array_append(arr, argument[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return arr;
|
2022-12-16 09:18:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function array_clone(arr) {
|
|
|
|
var _res = array_create(array_length(arr));
|
|
|
|
for( var i = 0; i < array_length(arr); i++ ) {
|
|
|
|
_res[i] = arr[i];
|
|
|
|
}
|
|
|
|
return _res;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|