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
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
language: node_js
node_js:
- "6"

addons:
chrome: stable

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

services:
- xvfb
before_install:
npm install karma-cli -g
npm install karma-cli -g
script:
- npm run start
69 changes: 35 additions & 34 deletions js/list.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
/**
* List
* @author donaldyang
*/

function List(head, tail) {
this.head = head || 0;
this.tail = tail || null;
}

// Returns a new List containing the array.
List.list = function (array) {
var sentinel = new List(),
len = array.length,
p, i;

p = sentinel;
for (i = 0; i < len; i++) {
p.tail = new List(array[i]);
p = p.tail;
}
return sentinel.tail;
}

// Returns a readable String for THIS.
List.prototype.toString = function () {
var res = '', L;
res += '[';
for (L = this; L !== null; L = L.tail) {
res = res + ' ' + L.head;
}
res += ' ]';
return res;
};
/**
* List
* @author donaldyang
*/

function List(head, tail) {
this.head = head || 0;
this.tail = tail || null;
}

// Returns a new List containing the array. [4, 6, 7, 3, 8]
List.list = function (array) {
var sentinel = new List(),
len = array.length,
p, i;

p = sentinel;
for (i = 0; i < len; i++) {
p.tail = new List(array[i]);
p = p.tail;
}
return sentinel.tail;
};

// Returns a readable String for THIS.
List.prototype.toString = function () {
var res = '', L;
res += '[';
for (L = this; L !== null; L = L.tail) {
res = res + ' ' + L.head;
}
res += ' ]';
return res;
};

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "test",
"main": "index.js",
"scripts": {
"test": "karma start"
"test": "karma start",
"start": "karma start --single-run"
},
"repository": {
"type": "git",
Expand Down
75 changes: 48 additions & 27 deletions quz/quz.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
/**
* dcate
* A list consisting of elements of A followed by the
* elements of B. May modify items of A.
* Don't use 'new'
* @param {List} A
* @param {List} B
* @returns {List}
*/
function dcate(A, B) {
/** Fill in here **/
}

/**
* sub
* The sublist consisting of LEN items from list L,
* beginning with item #START (where the first item is #0).
* Does not modify the original list elements.
* it is an error if the desired items don't exist.
* @param {List} L
* @param {Number} start
* @param {Number} len
* @returns {List}
*/
function sub(L, start, len) {
/** Fill in here **/
}
/**
* dcate
* A list consisting of elements of A followed by the
* elements of B. May modify items of A.
* Don't use 'new'
* @param {List} A
* @param {List} B
* @returns {List}
*/
// var A = List.list([4, 6, 7, 3, 8]),
// B = List.list([3, 2, 5, 9]),
// C = List.list([19, 8, 7, 3, 2]);
function dcate(A, B) {
let p = A;
// p:A中的最末尾元素
while (p.tail) {
p = p.tail
}
// 将B添加到A的尾巴
p.tail = B;
return A
}

/**
* sub
* The sublist consisting of LEN items from list L,
* beginning with item #START (where the first item is #0).
* Does not modify the original list elements.
* it is an error if the desired items don't exist.
* @param {List} L
* @param {Number} start
* @param {Number} len
* @returns {List}
*/
function sub(L, start, len) {
let p = L; // 当前遍历的元素
let i = 0; // 第N个元素
let array = [];
while (p && p.head) {
// 当元素处于开始到结束之间,array增加head属性
if (i >= start && i <= start + len) {
array.push(p.head)
}
p = p.tail;
i++
}
return List.list(array)
}