0

Help me refactoring this code

function func(s, a, b) { if (s.match(/^$/)) { return -1; } var i = s.length -1; var aIndex = -1; var bIndex = -1; while ((aIndex == -1) && (bIndex == -1) && (i > 0)) { if (s.substring(i, i +1) == a) { aIndex = i; } if (s.substring(i, i +1) == b) { bIndex = i; } i = i - 1; } if (aIndex != -1) { if (bIndex == -1) { return aIndex; } else { return Math.max(aIndex, bIndex); } } if (bIndex != -1) { return bIndex; } else { return -1; } }

24th Feb 2020, 9:53 PM
Roman Moskvin
Roman Moskvin - avatar
1 Respuesta
+ 2
to attract more answer you'll meed to 1 save it in code bits/playground 2 use indentation and finally, edit the question by linking the code here, and explain what the code does at the current state is kinda hard to see whats going on, some potential answerer may leave without analyzing your code at all.
24th Feb 2020, 10:00 PM
Taste
Taste - avatar