So as you guys might aware, I'm not a pro at JS and recently I had come across a question, where they claimed that the below method can be further reduced and can be written in 4-5 lines max! The original function was little bigger, and I have reduced it to this level.
Can you guys help me out with this?
function func(s, a, b) {
var match_empty=/^$/ ;
if (s.match(match_empty))
return -1;
else {
var aIndex = s.indexOf(a), bIndex = s.indexOf(b);
if (aIndex != -1)
return (aIndex != -1) ? ((bIndex == -1) ? aIndex : Math.max(aIndex, bIndex)) : ((bIndex != -1) ? bIndex : -1);
}
};
No responses yet.