New code snippets for JavaScript and Python have arrived... First off, is the quick removal of empty elements within a list or an Array given various criteria. Very useful for this purpose is the usage of type-casting functions such as Number(), Boolean(),... Take this example, where non-capturing groups result in empty string elements:
To archive the same effect in JavaScript, the handy 'filter' function can be used. 'filter' is loaded onto the Array.prototype chain since JS version 1.6 (and thus available in all modern browsers) (See prototypal inheritance if you are unfamiliar with prototype chains)
To generically check for empty elements in an array, the quickest way would be to pass Boolean: Lastly, I implemented PHP's trim function in JavaScript, afaik the shortest, fastest implementation. Basically the fundamental difference to JavaScript's trim is that the function allows for passing a character-list upon which the trimming left and right to the string proceeds until the first character which is not contained in the character-list. Thus passing a character list overrides the internal whitespace character list of the function. Apparently this list of whitespace char's is virtually the same in JS and PHP (Code example for testing this is provided in the gist above).
To archive the same effect in JavaScript, the handy 'filter' function can be used. 'filter' is loaded onto the Array.prototype chain since JS version 1.6 (and thus available in all modern browsers) (See prototypal inheritance if you are unfamiliar with prototype chains)
To generically check for empty elements in an array, the quickest way would be to pass Boolean: Lastly, I implemented PHP's trim function in JavaScript, afaik the shortest, fastest implementation. Basically the fundamental difference to JavaScript's trim is that the function allows for passing a character-list upon which the trimming left and right to the string proceeds until the first character which is not contained in the character-list. Thus passing a character list overrides the internal whitespace character list of the function. Apparently this list of whitespace char's is virtually the same in JS and PHP (Code example for testing this is provided in the gist above).