-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelperService.js
More file actions
47 lines (39 loc) · 1.5 KB
/
Copy pathhelperService.js
File metadata and controls
47 lines (39 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
( function () {
/*eslint-disable */
"use strict";
angular.module( "HelperService" )
.factory( "ArrayService", [ function () {
var sortByKey = function ( array, key1 ) {
return array.sort( function ( a, b ) {
var x1 = a[ key1 ];
var x2 = b[ key1 ];
if ( x1 !== x2 ) {
if ( x1 < x2 ) return -1; // x1 goes nearer to the top
if ( x1 > x2 ) return 1; // x1 goes nearer to the bottom
return 0; // both are the same
}
} );
},
findIndexByKeyValue = function ( array, key, valuetosearch ) {
for ( var i = 0; i < array.length; i++ ) {
if ( array[ i ][ key ] === valuetosearch ) {
return i;
}
}
return null;
},
combineArray = function ( a, b ) {
// `b` onto `a`:
a.reduce( function ( coll, item ) {
coll.push( item );
return coll;
}, b );
return b;
}
return {
sortByKey: sortByKey,
findIndexByKeyValue: findIndexByKeyValue,
combineArray: combineArray
}
} ] )
} )();