| 1234567891011121314151617181920212223242526272829 |
- export default class ArrayUtils {
- /**
- * Trie un tableau
- *
- * @param array
- * @param reverse
- */
- public static sort(array: Array<any>, reverse: boolean = false): Array<Object> {
- return array.sort((a, b) => {
- return ((a < b) ? -1 : (a > b ? 1 : 0)) * (reverse ? -1 : 1)
- })
- }
- /**
- * Trie un tableau d'objets selon une propriété commune
- *
- * @param array Une array d'objets
- * @param property Le nom d'une propriété possédée par tous les objets
- * @param reverse
- */
- public static sortObjectsByProp(array: Array<Object>, property: string, reverse: boolean = false): Array<Object> {
- return array.sort((a: any, b: any) => {
- return ((a[property] < b[property]) ? -1 : (a[property] > b[property] ? 1 : 0)) * (reverse ? -1 : 1)
- })
- }
- }
|