Title :
Number-like counter(返回数字类型的counter类)
Description:
You’re going to implement a simple counter class. The counter will start at zero, and every time its incr
method is called, it will increase by 1.
There’s one caveat: Your counter must act like a number and support arithmetic operations and comparisons.
要求创建一个counter类,和它的一个成员方法incr,当counter的实例每次调用incr时,它的值都会加1.
For example:
var c = new Counter();
c.incr(); // counter is now at 1
c + 1; // 2
c > 1; // false
c > 0; // true
c == 1; // true
Math.sqrt(c); // 1
You are not required to support equality comparison between two Counter
instances.
Continue reading →