稍微改了一下,更漂亮些。

回答: 再对比一下相应的javascript代码柯西2012-06-20 22:59:22

function countingoff(count, steps) {

    var people = []

    while (count) { people.unshift(count--)}

    Array.prototype.pop = function(idx) { return this.splice(idx, 1)[0] }

    var idx = 0

    while (people.length) {

        idx = (idx + steps - 1)%people.length

        console.log("removed: #", people.pop(idx), ", left: ", people)

    }

}

// example

countingoff(25, 7)

请您先登陆,再发跟帖!