I have string coming from the server:
//A
123|155-244
- The first numbers always means 'Red'
- Numbers after
|always means 'Green' - Numbers after
-always means 'Blue'
The issue here is that Green and Blue can come back in either order:
//B
123-244|155
Or they can be missing entirely:
//C
123|155
I need a function that returns one array/object to make things easy:
//A
var result = {red:"123", green:"155", blue:"244"}
//B
var result = {red:"123", green:"155", blue:"244"}
//C
var result = {red:"123", green:"155", blue:"0"}
I've tried two functions, one to get Green and the other Blue, but I realized that doesn't work properly depending on the order they appear in the string.
var getGreen = function(myvar){
return myvar.split('-');
};
var getBlue = function(myvar){
return myvar.split('|');
};
Doing this sometimes causes my object to look like this:
var result = {red:"123", green:"155", blue:"244|155"}
How should I proceed?