I put together a little function rangein JS. I tested it in Chrome 19, FF, and IE (7-9) and it works well. The question I have is related to the operator while.
function range(from,to,step)
{
'use strict';
var sCode,eCode,result;
result = [];
step = (!step || isNaN(step) || step === 0 ? 1 : step);
sCode = (''+from).charCodeAt(0);
eCode = (''+to).charCodeAt(0);
step *= (sCode > eCode && step > 0 ? -1 : 1);
do
{
if (String.fromCharCode(sCode))
{
result.push(String.fromCharCode(sCode));
}
}while((step > 0 && eCode >= (sCode+=step)) || (step < 0 && eCode <= (sCode+=step)));
return result;
}
I remember reading a question for some time about how JS handles control flow constructors and logical operators. I think this has something to do with checking if the object had a specific method, and if so, using its return value ( if (event.returnValue && e.returnValue === true)kind of things).
I can no longer find this question, here is what I wanted to know:
while((step > 0 && eCode >= (sCode+=step)) || (step < 0 && eCode <= (sCode+=step)));
, , , , , step < 0 , && eCode >= (sCode+=step) , sCode .
step , sCode /. , , sCode eCode. , , .
, ? , ( ) sCode ?
( ). , JavaScript .
, .
( , ):
- charCode JavaScript? google , JS ,
5999999999989759, , , , . from undefined, , jslint from.toString().charCodeAt(0);, , , , undefined toString, (''+from).charCodeAt(0); return U ? , toString?