opt-cc/api/middleware/util.js

29 lines
551 B
JavaScript

"use strict";
const sortCollectionBy = (collection, key) => {
collection.sort((a, b) => {
a = a[key].toLowerCase();
b = b[key].toLowerCase();
if (a < b) return -1;
if (a > b) return 1;
return 0;
});
return collection;
};
const arrayContains = (arr, user) => {
let i = 0, count = arr.length, matchFound = false;
for(; i < count; i++) {
if (arr[i] === user) {
matchFound = true;
break;
}
}
return matchFound;
};
exports.sortCollection = sortCollectionBy;
exports.arrayContains = arrayContains;