off by one in Ox.encodeBase26
This commit is contained in:
parent
f030596468
commit
b6411d485a
1 changed files with 10 additions and 2 deletions
|
@ -4,14 +4,22 @@
|
|||
Ox.encodeBase26 <b> Encode a number as bijective base26
|
||||
See <a href="http://en.wikipedia.org/wiki/Bijective_numeration">
|
||||
Bijective numeration</a>.
|
||||
> Ox.encodeBase26(0)
|
||||
''
|
||||
> Ox.encodeBase26(1)
|
||||
'A'
|
||||
> Ox.encodeBase26(26)
|
||||
'Z'
|
||||
> Ox.encodeBase26(27)
|
||||
'AA'
|
||||
> Ox.encodeBase26(4461)
|
||||
'FOO'
|
||||
@*/
|
||||
Ox.encodeBase26 = function(number) {
|
||||
var string = '';
|
||||
while (number) {
|
||||
string = String.fromCharCode(64 + number % 26) + string;
|
||||
number = parseInt(number / 26);
|
||||
string = String.fromCharCode(65 + (number - 1) % 26) + string;
|
||||
number = Math.floor((number - 1) / 26);
|
||||
}
|
||||
return string;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue