I have the following code that converts a string that looks like:
aaa-bbb|ccc-ddd|eee-fff
to two strings that look like:
aaa|ccc|eee
and
bbb|ddd|fff
The code works fine, but I am wondering if I probably missed some string/array functions that can makes the job in fewer operations / or with faster runtime.
var id = "HEL-CAS|MAD-STO|XXX-YYY"
var splittedId = id.split('|');
var from = "",
to = "";
$(splittedId).each(function(a, b) {
from = from + b.split("-")[0] + "|";
to = to + b.split("-")[1] + "|";
});
from = from.substring(0, from.length - 1);
to = to.substring(0, to.length - 1);