I'm using an API which returns text in the following format:
#start
#p 09060 20131010
#p 09180 AK
#p 01001 19110212982
#end
#start
#p 09060 20131110
#p 09180 AB
#p 01001 12110212982
#end
I'm converting this to a list of objects:
var result = data.match(/#start[\s\S]+?#end/ig).map(function(v){
var lines = v.split('\n'),
ret = {};
$.each(lines, function(_, v2){
var split = v2.split(' ');
if(split[1] && split[2])
ret[split[1]] = split[2];
});
return ret;
});
My concern is that the API returns quite a lot of data, therefore I would like some feedback regarding on how to improve the performance.
For instance, is there any way to reduce the mapping complexity from O(N2) to O(N)?
Also, please suggest regex improvements :)