SOURCE

class Statck {
    constructor() {
        this.count = 0;
        this.items = {}
    }
    isEmpty() {
        return this.count === 0
    }
    push(item) {
        this.items[this.count] = item;
        this.count++
    }
    pop() {
        if (this.isEmpty()) {
            return undefined
        }
        this.count--;
        const result = this.items[this.count];
        delete this.items[this.count];
        return result;
    }
    peek() {
        if (this.isEmpty()) {
            return undefined
        }
        return this.items[0]
    }
    clear() {
        this.count = 0;
        this.items = {}
    }
    size() {
        return this.count
    }
    toString() {
        if (this.isEmpty()) {
            return ''
        }
        let str = `${this.items[0]}`
        for (let i = 1; i < this.count; i++) {
            str = `${str},${this.items[i]}`
        }
        return str;
    }
}

function formateNumber(number, base) {
    const statck = new Statck();
    const digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    let newNumber = number;
    let rem;
    let str = ""
    if (!(base >= 2 && base <= 36)) {
        return ''
    }
    while (newNumber > 0) {
        rem = Math.floor(newNumber % base);
        statck.push(rem);
        newNumber = Math.floor(newNumber / base)
    }
    while (!statck.isEmpty()) {
        str += digits[statck.pop()]
    }
    return str;
}

const statck = new Statck();
statck.push('John')
statck.push('Jack')
statck.peek();
console.log(statck.peek())
console.log(formateNumber(100345, 8))
console 命令行工具 X clear

                    
>
console