| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 | /** * Created by Tony on 2017/4/5. */var test = require('tape');var headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';test('test private 1', function(t){    private_getCellIdxStr = function(idx, pre){        var rst = 'A', prefix = '', tmpIdx = idx;        if (tmpIdx >= 26) {            var ti = Math.floor(tmpIdx / 26), tj = tmpIdx % 26;            if (ti <= 26) {                rst = pre + headerStr[ti - 1] + headerStr[tj];            } else {                //rst = private_getCellIdxStr2(ti, 'A' + pre) + headerStr[tj];                rst = private_getCellIdxStr2(ti, 'A' + pre) + headerStr[tj];            }        } else {            rst = pre + headerStr[tmpIdx % 26];        }        return rst;    };    private_getCellIdxStr2 = function(idx){        var rst = 'A';        if (idx < 26) {            rst = headerStr[idx];        } else if (idx < 26*26+26) {            var ti = Math.floor(idx / 26), tj = idx % 26;            rst = headerStr[ti - 1] + headerStr[tj];        } else if (idx < 26*26*26+26) {            var ti = Math.floor(idx / (26*26)), tj = Math.floor((idx - ti * 26*26) / 26), tk = idx % 26;            rst = headerStr[ti - 1] + headerStr[tj-1] + headerStr[tk];        }        return rst;    };    t.equal(private_getCellIdxStr2(0, ''), 'A');    t.equal(private_getCellIdxStr2(20, ''), 'U');    t.equal(private_getCellIdxStr2(25, ''), 'Z');    t.equal(private_getCellIdxStr2(26, ''), 'AA');    t.equal(private_getCellIdxStr2(27, ''), 'AB');    t.equal(private_getCellIdxStr2(51, ''), 'AZ');    t.equal(private_getCellIdxStr2(52, ''), 'BA');    t.equal(private_getCellIdxStr2(77, ''), 'BZ');    t.equal(private_getCellIdxStr2(103, ''), 'CZ');    t.equal(private_getCellIdxStr2(675, ''), 'YZ');    t.equal(private_getCellIdxStr2(676, ''), 'ZA');    t.equal(private_getCellIdxStr2(701, ''), 'ZZ');    t.equal(private_getCellIdxStr2(702, ''), 'AAA');    t.equal(private_getCellIdxStr2(727, ''), 'AAZ');    t.equal(private_getCellIdxStr2(728, ''), 'ABA');    t.end();})
 |