var ifChecks = function( i )
{
if( i === 23 )
{
// implementation
}
else if ( i === 300 )
{
// implementation
}
else if ...
}
I have this kind of long if else chain (app. 60 checks) in javascript code, this lengthy chain is inefficient as if 60th check comes as input, then it has to unnecessarily go through 59 checks, so I thought to implement like this.
var implobj = { 23 : handleimpl1,
300 : handleimpl2,
.
.
.
}
var handleImpl = function( i )
{
implobj[i]();
}
Is there any other way better than this solution which can be implemented in javascript?
Note: input is not sequential number, otherwise I could have used array instead of object.
I would use your idea, coded slightly differently like this: