How can I tokenise a string of values into an array?
// Handles missing values and irregular whitespace
const tokenise = (s, d= ',') => s.split(d).map(v => v.trim()).filter(v => v)
const stringData = ", mladen, asad, robin, ben,roger, ardit , alexis, ,"
const actualList = tokenise(stringData)
const expectList = ["mladen", "asad", "robin", "ben", "roger", "ardit", "alexis"]
expect(actualList).toEqual(expectList)
PreviousNested Ternaries vs Switch StatementsNextHow can I parse a template string into its constant and variable parts?
Last updated
Was this helpful?