Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
coverage
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ node_js:

addons:
chrome: stable
services:
- xvfb

before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start

before_install:
Expand Down
8 changes: 6 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'quz/*.js': ['coverage']
},
coverageReporter: {
type : 'html',
dir : 'coverage/'
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
reporters: ['progress', 'coverage'],


// web server port
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
},
"homepage": "https://github.com/FE-star/homework1#readme",
"devDependencies": {
"karma": "^1.7.0",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-mocha": "^1.3.0",
"mocha": "^3.5.0",
"should": "^11.2.1"
Expand Down
27 changes: 25 additions & 2 deletions quz/quz.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
* @returns {List}
*/
function dcate(A, B) {
/** Fill in here **/
function getListLast (list) {
if (!list.tail) {
return list
} else {
return getListLast(list.tail)
}
}
let lastA = getListLast(A)
lastA.tail = B
return A
}

/**
Expand All @@ -23,5 +32,19 @@ function dcate(A, B) {
* @returns {List}
*/
function sub(L, start, len) {
/** Fill in here **/
if (!L || (!start && start !== 0) || (!len && len !== 0)) {
throw new Error('缺少参数')
}
function getListByIndex (list, index, from = 0) {
if (from === index) {
return list
} else {
from ++
return list.tail && getListByIndex(list.tail, index, from)
}
}
let startList = getListByIndex(L, start)
let endList = getListByIndex(startList, (start + len - 1), start)
endList && (endList.tail = null)
return startList
}
3 changes: 3 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ describe('unit test for quz.js', function () {
it('should get the sublist consisting of LEN items from list L', function () {
C.toString().should.equal('[ 19 8 7 3 2 ]');
sub(C, 3, 2).toString().should.equal('[ 3 2 ]');
should.throws(() => sub(C, 3), function (err) {
return err.message.includes('缺少参数')
});
C.toString().should.equal('[ 19 8 7 3 2 ]');
});
});
Expand Down