From 570c11a47fd2a8a06754a1549511b01bdfef338f Mon Sep 17 00:00:00 2001 From: louly Date: Sat, 3 Aug 2019 11:16:40 +0800 Subject: [PATCH 1/3] lly: do homework1 --- .idea/vcs.xml | 6 +++++ .travis.yml | 5 ++-- js/list.js | 69 ++++++++++++++++++++++++----------------------- quz/quz.js | 75 ++++++++++++++++++++++++++++++++------------------- 4 files changed, 92 insertions(+), 63 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index f52bbce..5621d4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ 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 \ No newline at end of file + npm install karma-cli -g diff --git a/js/list.js b/js/list.js index 356bcf9..6b8a01b 100755 --- a/js/list.js +++ b/js/list.js @@ -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; +}; + diff --git a/quz/quz.js b/quz/quz.js index 624e7de..443bba2 100755 --- a/quz/quz.js +++ b/quz/quz.js @@ -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) +} From 22711d391f373c29c0f7ea08e4463d8dd2c1ba8f Mon Sep 17 00:00:00 2001 From: louly Date: Sat, 3 Aug 2019 11:18:10 +0800 Subject: [PATCH 2/3] lly: bugfix homework1 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 5621d4e..0e3238d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,3 +13,5 @@ services: - xvfb before_install: npm install karma-cli -g +script: + - npm run test From 5cbf710f15eff6d1592c6c5e455debea96079386 Mon Sep 17 00:00:00 2001 From: louly Date: Sun, 4 Aug 2019 08:58:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?lly=EF=BC=9A=20finish=20homework1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 8 +------- package.json | 3 ++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0e3238d..751b943 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +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 script: - - npm run test + - npm run start diff --git a/package.json b/package.json index e80646a..da4fdf8 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "test", "main": "index.js", "scripts": { - "test": "karma start" + "test": "karma start", + "start": "karma start --single-run" }, "repository": { "type": "git",