Chalarangelo / 30-seconds-of-code

Short code snippets for all your development needs

Home Page:https://30secondsofcode.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CSVToArray will return an empty item for documents ending with \n

chepo92 opened this issue · comments

https://github.com/30-seconds/30-seconds-of-code/blob/master/snippets/CSVToArray.md

CSVToArray('a,b\nc,d\n'); // [ [ 'a', 'b' ], [ 'c', 'd' ], [ '' ] ]

The same problem will arise if the document is starting with \n as well.

Answerig myself, .filter(Boolean) will get rid of them, getting those nulls/empty may sometimes be the intended behaviour.