From ad77475251c3516dd5851a08655be79d7bf76245 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 25 Jul 2018 15:11:25 +0200 Subject: Sort video captions --- client/src/app/shared/misc/utils.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'client/src/app/shared/misc/utils.ts') diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts index 8381745f5..018271efe 100644 --- a/client/src/app/shared/misc/utils.ts +++ b/client/src/app/shared/misc/utils.ts @@ -101,7 +101,19 @@ function removeElementFromArray (arr: T[], elem: T) { if (index !== -1) arr.splice(index, 1) } +function sortBy (obj: any[], key1: string, key2?: string) { + return obj.sort((a, b) => { + const elem1 = key2 ? a[key1][key2] : a[key1] + const elem2 = key2 ? b[key1][key2] : b[key1] + + if (elem1 < elem2) return -1 + if (elem1 === elem2) return 0 + return 1 + }) +} + export { + sortBy, objectToUrlEncoded, getParameterByName, populateAsyncUserVideoChannels, -- cgit v1.2.3