Javascript Array flatMap(mapFunc)
Array.prototype.flatMap = function(mapFunc) { var result = [] for (let item of this) { let tokens = mapFunc(item) result = result.concat(tokens)/*from w w w .j a v a2 s. c o m*/ } return result }