I came across following code
function currentSlideFromParams() {
var result;
if (result = window.location.hash.match(/#([0-9]+)/)) {
return result[result.length - 1] - 1;
}
}
It is clear that this code is written by a ruby developer. However what is ruby idiomatic is not necessarily JavaScript idiom. Secondly the code complains when I run through Jslint because it warns about having an assignment inside conditional check.
Please suggest refactored code that is as per JavaScript idiom.
This would assign it first. I don’t see what the big deal is, though.. you don’t really have to obey jslint’s rules.