I am having difficulty "compressing" the results of my grammar by stripping out null values and embedded arrays using Javascript. I am using the Nearley grammar checker which can run JS functions after a sentence is matched. Unfortunately you get the results of the full parse as a series of arrays. The following is an example of the output
[
[
[
[
[
[
[ [ 'climb'], [ [ null, 'to' ] ] ],
[ [ null, [ 'alt' ] ] ],
[ 332, [ null, [ 'km' ] ] ]
]
],
[ null ]
]
]
]
]
I would like to remove all those null values and possibly "compress" all those arrays to something of the form:
[
[ 'climb', 'to' ],
[ 'alt', 332, 'km' ]
]
Or something similar. I have tried using various filter methods without success.
'alt'? why not only a sinlge array? what have you tried?alt'alt'be on its own line in the output array?climbtomay be considered verbs andalt 332 kmmay be considered the target or subject[[ 'climb', 'to' ], [ 'alt' ], [ 332, 'km' ]]was the most logic result for a generically working approach. The edited output of[[ 'climb', 'to' ], [ 'alt', 332, 'km' ]]does not make any sense at all.