@@ -618,27 +618,25 @@ export const getFilteredChartVersions = (charts, selectedChartType) =>
618
618
} ) )
619
619
620
620
/**
621
- * This function takes a list of strings and checks if the strings
622
- * have prefix matches in the list of prefixes
623
- * @param strings check if a @string has a prefix match in @prefixes
624
- * @param prefixes list of prefixes
625
- * @returns array of booleans corresponding to each string in @strings
621
+ * Removes nulls from the arrays in the provided object
622
+ * @param {object } object from which we need to delete nulls in its arrays
623
+ * @returns object after removing (in-place) the null items in arrays
626
624
*/
627
- export const getPrefixMatches = ( strings : string [ ] , prefixes : string [ ] ) => {
628
- // NOTE: a trie could have been used but it would have been memory inefficient
629
- const set = new Set ( prefixes )
630
- return strings . map ( ( string ) => {
631
- for ( let index = 0 ; index <= string . length ; index ++ ) {
632
- // NOTE: slice in v8 is O(1) https://mrale.ph/blog/2016/11/23/making-less-dart-faster.html
633
- // due to using SlicedString construct that only keeps pointer to original string
634
- // alternative tries would be tree structure (hard to cache)
635
- const slice = string . slice ( 0 , index )
636
- if ( set . has ( slice ) ) {
637
- return true
638
- }
639
- }
640
- return false
625
+ export const recursivelyRemoveNullsFromArraysInObject = ( object : object ) => {
626
+ // NOTE: typeof null === 'object'
627
+ if ( typeof object !== 'object' || ! object ) {
628
+ return object
629
+ }
630
+ if ( Array . isArray ( object ) ) {
631
+ return object . filter ( ( item ) => {
632
+ recursivelyRemoveNullsFromArraysInObject ( item )
633
+ return ! ! item
634
+ } )
635
+ }
636
+ Object . keys ( object ) . forEach ( ( key ) => {
637
+ object [ key ] = recursivelyRemoveNullsFromArraysInObject ( object [ key ] )
641
638
} )
639
+ return object
642
640
}
643
641
644
642
const _joinObjects = ( A : object , B : object ) => {
@@ -655,8 +653,8 @@ const _joinObjects = (A: object, B: object) => {
655
653
}
656
654
657
655
/**
658
- * Merges @ objects into one
659
- * @param objects list of js objects
656
+ * Merges the objects into one object
657
+ * @param { object[] } objects list of js objects
660
658
* @returns object after the merge
661
659
*/
662
660
export const joinObjects = ( objects : object [ ] ) => {
@@ -679,11 +677,10 @@ const buildObjectFromPathTokens = (index: number, tokens: string[], value: any)
679
677
: { [ key ] : buildObjectFromPathTokens ( index + 1 , tokens , value ) }
680
678
}
681
679
682
- // TODO: learn how to write js doc comments
683
680
/**
684
- * Builds an object from the provided @ path
685
- * @param path JSON pointer path of the form /path/to/1/...
686
- * @param value property value
681
+ * Builds an object from the provided path
682
+ * @param { string } path JSON pointer path of the form /path/to/1/...
683
+ * @param { any } value property value
687
684
* @returns final object formed from the path
688
685
*/
689
686
export const buildObjectFromPath = ( path : string , value : any ) => {
@@ -708,21 +705,6 @@ export const getRegexMatchPositions = (string: string, regex: RegExp): number[]
708
705
return [ pos , ...getRegexMatchPositions ( nextToken , regex ) . map ( ( n ) => n + pos + 1 ) ]
709
706
}
710
707
711
- // TODO: write js doc comment
712
- export const powerSetOfSubstringsFromStart = ( strings : string [ ] ) =>
713
- strings . flatMap ( ( key ) => {
714
- const _keys = [ key ]
715
- const positions = getRegexMatchPositions ( key , / \. | \[ | \] / g)
716
- positions . forEach ( ( position ) => {
717
- const ch = key . charAt ( position )
718
- if ( ch === ']' ) {
719
- return
720
- }
721
- _keys . push ( key . slice ( 0 , position ) )
722
- } )
723
- return _keys
724
- } )
725
-
726
708
/**
727
709
* Returns a debounced variant of the function
728
710
*/
0 commit comments