【发布时间】:2017-03-02 00:48:34
【问题描述】:
首先你要创建三个函数,作为 Array 类的原型返回以下内容:
toTwenty()` returns `[1, 2, 3 . . . 20]
下面是测试用例
describe('Binary Search to traverse an ordered list, effectively', function() {
describe('Populate the arrays with valid content', function() {
it('should create an array from 1 to 20, with intervals of 1', function() {
expect(oneToTwenty[0]).toBe(1);
expect(oneToTwenty[19]).toBe(20);
expect(oneToTwenty.length).toBe(20);
for(var i = 0; i < oneToTwenty.length - 1;i++) {
expect(oneToTwenty[i + 1] - oneToTwenty[i]).toBe(1);
}
});
这是下面的代码是我的代码,但我不断得到
var oneToTwenty = [].toTwenty();
"TypeError: Object has no method 'toTwenty'"
这是我的代码
function oneToTwenty(){
}
oneToTwenty.prototype.toTwenty = function(){
var start = 1;
var end = 20;
var oneToTwenty = [];
for(var i = start; i <= end; i += 1){
oneToTwenty.push(i);
}
return oneToTwenty;
}
【问题讨论】:
标签: javascript class prototype