]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/core-utils/common/array.ts
Refactor my actor avatar edit
[github/Chocobozzz/PeerTube.git] / shared / core-utils / common / array.ts
CommitLineData
dd6d2a7c
C
1function findCommonElement <T> (array1: T[], array2: T[]) {
2 for (const a of array1) {
3 for (const b of array2) {
4 if (a === b) return a
5 }
6 }
7
8 return null
9}
10
e3d6c643
C
11// Avoid conflict with other toArray() functions
12function arrayify <T> (element: T | T[]) {
13 if (Array.isArray(element)) return element
14
15 return [ element ]
16}
17
690bb8f9
C
18// Avoid conflict with other uniq() functions
19function uniqify <T> (elements: T[]) {
20 return Array.from(new Set(elements))
21}
22
dd6d2a7c 23export {
690bb8f9 24 uniqify,
e3d6c643
C
25 findCommonElement,
26 arrayify
dd6d2a7c 27}