opt-cc/api/tools/util.js

29 lines
610 B
JavaScript
Raw Normal View History

2017-06-08 13:14:53 +02:00
"use strict";
2017-05-10 11:04:06 +02:00
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;
};
2017-10-21 11:32:25 +02:00
const playerArrayContains = (arr, item) => {
2017-10-20 23:42:41 +02:00
let i = 0, count = arr.length, matchFound = false;
for(; i < count; i++) {
2017-10-21 11:32:25 +02:00
if (arr[i].name === item.name && arr[i].fraction === item.fraction) {
2017-10-20 23:42:41 +02:00
matchFound = true;
break;
}
}
return matchFound;
};
2017-05-10 11:04:06 +02:00
exports.sortCollection = sortCollectionBy;
2017-10-21 11:32:25 +02:00
exports.arrayContains = playerArrayContains;