@@ -426,7 +426,7 @@ if (mainContainer.pa && console && console.warn) {
426
426
condition . condition = pa . EqualTo3 ( condition . condition ) ; //transforms an explicit value into an === evaluation
427
427
}
428
428
429
-
429
+
430
430
const valueToEvaluate = condition . column ? item [ condition . column ] : item ;
431
431
if ( ! item || ! condition . condition ( valueToEvaluate ) ) { //if one condition is not fulfilled, just return false;
432
432
return false ;
@@ -981,7 +981,7 @@ if (mainContainer.pa && console && console.warn) {
981
981
var l = value . length ;
982
982
while ( l -- ) {
983
983
valueCaseInsensitive = value [ l ] . toUpperCase ( ) ;
984
- if ( ( val + '' ) . toUpperCase ( ) . indexOf ( valueCaseInsensitive ) === - 1 ) {
984
+ if ( ( val + '' ) . toUpperCase ( ) . indexOf ( valueCaseInsensitive ) === - 1 ) {
985
985
return false ;
986
986
}
987
987
}
@@ -1000,7 +1000,7 @@ if (mainContainer.pa && console && console.warn) {
1000
1000
var l = value . length ;
1001
1001
while ( l -- ) {
1002
1002
valueCaseInsensitive = value [ l ] . toUpperCase ( ) ;
1003
- if ( ( val + '' ) . toUpperCase ( ) . indexOf ( valueCaseInsensitive ) > - 1 ) {
1003
+ if ( ( val + '' ) . toUpperCase ( ) . indexOf ( valueCaseInsensitive ) > - 1 ) {
1004
1004
return false ;
1005
1005
}
1006
1006
}
@@ -1375,7 +1375,7 @@ if (mainContainer.pa && console && console.warn) {
1375
1375
if ( sortConditions . hasOwnProperty ( property ) ) {
1376
1376
1377
1377
//transform the keys into a better object with properties Column and SortOrder
1378
- var value = sortConditions [ property + '' ] . toUpperCase ( ) ;
1378
+ var value = sortConditions [ property + '' ] . toUpperCase ( ) ;
1379
1379
1380
1380
if ( ! mainContainer . pa . Sort . _validSortConfigStrings . indexOf ( sortConditions [ property ] ) === - 1 ) {
1381
1381
throw new Error ( "PowerArray Configuration Error => Invalid sort direction for property " + property + ": '" + sortConditions [ property ] + "'" ) ;
@@ -1598,7 +1598,7 @@ if (mainContainer.pa && console && console.warn) {
1598
1598
return pa . prototypedFunctions_Array . Where . call ( this , whereConditions , true , true ) ;
1599
1599
} ,
1600
1600
FirstIndex : function ( whereConditions ) { // jshint ignore:line
1601
- if ( typeof ( whereConditions ) === 'string' ) {
1601
+ if ( typeof ( whereConditions ) === 'string' || typeof ( whereConditions ) === 'number' ) {
1602
1602
//transform single match strings to an EqualTo3
1603
1603
whereConditions = EqualTo3 ( whereConditions ) ;
1604
1604
}
@@ -1607,6 +1607,26 @@ if (mainContainer.pa && console && console.warn) {
1607
1607
}
1608
1608
return pa . prototypedFunctions_Array . Where . call ( this , whereConditions , true , true , true ) ;
1609
1609
} ,
1610
+ /*
1611
+ returns an array of numbers, with the index position of all matching elements
1612
+ given:
1613
+ var arr = [1,2,3,4,2,56,2,64];
1614
+ arr.AllIndexes(2) => [1,4,6];
1615
+ arr.AllIndexes(325) => [];
1616
+ arr.AllIndexes(1) => [0]
1617
+
1618
+ */
1619
+ AllIndexes : function ( whereConditions ) {
1620
+ var newArray = this ;
1621
+ var foundIndex = newArray . FirstIndex ( whereConditions ) ;
1622
+ var result = [ ] , toSkip = 0 ;
1623
+ while ( ( foundIndex = newArray . FirstIndex ( whereConditions ) ) !== undefined ) {
1624
+ result . push ( foundIndex + toSkip ) ;
1625
+ newArray = this . Skip ( toSkip + foundIndex + 1 ) ;
1626
+ toSkip += foundIndex + 1 ;
1627
+ }
1628
+ return result ;
1629
+ } ,
1610
1630
AttachIndex : function ( getterName , fromProp ) {
1611
1631
return pa . prototypedFunctions_Array . attachIndex . call ( this , getterName , fromProp ) ;
1612
1632
} ,
@@ -1649,8 +1669,8 @@ if (mainContainer.pa && console && console.warn) {
1649
1669
}
1650
1670
}
1651
1671
1652
- if ( arguments . length === 1 )
1653
- return result [ arguments [ 0 ] ] ; //return only the result, in order to avoid the duplication of the property name when only using 1 prop.
1672
+ if ( arguments . length === 1 )
1673
+ return result [ arguments [ 0 ] ] ; //return only the result, in order to avoid the duplication of the property name when only using 1 prop.
1654
1674
1655
1675
return result ;
1656
1676
@@ -1714,6 +1734,32 @@ if (mainContainer.pa && console && console.warn) {
1714
1734
Last : function ( ) {
1715
1735
var idx = this . length - 1 ;
1716
1736
return ( idx > - 1 ) ? this [ idx ] : null ;
1737
+ } ,
1738
+ /*returns an array of arrays, by splitting the current array by matching the first occurences of the passed whereconditions object
1739
+ given:
1740
+ arr = [1,2,3,4,0,2,3,6,3,0,5,2,5,54,0,2,6]
1741
+ condition = 0; its a number, but it could be any where condition or array of them
1742
+ arr.split(0) will return = [[1,2,3,4],[2,3,6,3],[5,2,5,54],[2,6]]
1743
+ */
1744
+ Split : function ( whereConditions ) {
1745
+ var result = [ ] , nextStartIdx = 0 ;
1746
+ var allIndexes = this . AllIndexes ( whereConditions ) ;
1747
+ var prevIndexVal = - 1 ;
1748
+ allIndexes . RunEach ( ( val , i ) => {
1749
+ var toTake = val - ( prevIndexVal + 1 ) ;
1750
+ result . push ( this . Take ( toTake , prevIndexVal < 0 ? 0 : prevIndexVal + 1 ) ) ;
1751
+ prevIndexVal = val ;
1752
+ } , null , true ) ;
1753
+
1754
+ if ( allIndexes . length === 0 )
1755
+ return [ this ] ;
1756
+
1757
+ var lastIndex = allIndexes . Last ( ) ;
1758
+ if ( lastIndex < this . length ) { //add the elements between the last index and the end of the array
1759
+ result . push ( this . Take ( this . length - lastIndex , lastIndex + 1 ) ) ;
1760
+ }
1761
+
1762
+ return result ;
1717
1763
}
1718
1764
} ;
1719
1765
0 commit comments