mirror of
https://github.com/alice-lg/alice-lg.git
synced 2024-05-11 05:55:03 +00:00
29 lines
438 B
JavaScript
29 lines
438 B
JavaScript
|
|
/**
|
|
* Intersect lists: [x | x <- A, x `elem` B]
|
|
*/
|
|
export function intersect(a, b) {
|
|
let res = [];
|
|
for (const e of a) {
|
|
for (const k of b) {
|
|
if (e==k) {
|
|
res.push(e);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
/**
|
|
* Resolve list with dict: [dict[x] or x | x <- L]
|
|
*/
|
|
export function resolve(dict, list) {
|
|
let result = [];
|
|
for (const e of list) {
|
|
result.push(dict[e]||e);
|
|
}
|
|
return result;
|
|
}
|
|
|