PeerTube/shared/core-utils/common/array.ts

28 lines
517 B
TypeScript
Raw Normal View History

2021-11-03 13:23:55 +00:00
function findCommonElement <T> (array1: T[], array2: T[]) {
for (const a of array1) {
for (const b of array2) {
if (a === b) return a
}
}
return null
}
2022-07-27 11:44:40 +00:00
// Avoid conflict with other toArray() functions
function arrayify <T> (element: T | T[]) {
if (Array.isArray(element)) return element
return [ element ]
}
2022-08-17 13:36:03 +00:00
// Avoid conflict with other uniq() functions
function uniqify <T> (elements: T[]) {
return Array.from(new Set(elements))
}
2021-11-03 13:23:55 +00:00
export {
2022-08-17 13:36:03 +00:00
uniqify,
2022-07-27 11:44:40 +00:00
findCommonElement,
arrayify
2021-11-03 13:23:55 +00:00
}