54 lines
1010 B
Plaintext
54 lines
1010 B
Plaintext
// Core 层 - 数组工具
|
|
// 提供数组操作的工具函数
|
|
|
|
// 检查数组是否包含元素
|
|
function array_contains(arr, item) {
|
|
foreach (i, v in arr) {
|
|
if (v == item) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// 查找数组元素索引
|
|
function array_indexOf(arr, item) {
|
|
foreach (i, v in arr) {
|
|
if (v == item) return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
// 数组去重
|
|
function array_unique(arr) {
|
|
local result = [];
|
|
local seen = {};
|
|
foreach (v in arr) {
|
|
if (!seen.rawin(v)) {
|
|
seen[v] <- true;
|
|
result.append(v);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// 数组过滤
|
|
function array_filter(arr, predicate) {
|
|
local result = [];
|
|
foreach (v in arr) {
|
|
if (predicate(v)) {
|
|
result.append(v);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// 数组映射
|
|
function array_map(arr, mapper) {
|
|
local result = [];
|
|
foreach (v in arr) {
|
|
result.append(mapper(v));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
print("Array utilities loaded");
|