From a16099a6786f29325639c4991b913b2425e9debb Mon Sep 17 00:00:00 2001 From: Jizu Sun Date: Fri, 26 Oct 2018 09:18:36 +0800 Subject: [PATCH 1/4] add two more katas for `[].fill()` from MDN --- katas/es6/language/array-api/fill.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/katas/es6/language/array-api/fill.js b/katas/es6/language/array-api/fill.js index 6fb502fb..9e87cf39 100644 --- a/katas/es6/language/array-api/fill.js +++ b/katas/es6/language/array-api/fill.js @@ -35,4 +35,22 @@ describe('`Array.prototype.fill` can fill up an array with one value', () => { assert.deepEqual(arr, [1, 42, 3]); }); + + it('is a mutable method, and will change this object itself', function() { + const arr = new Array(3); + //// arr.fill('foo') + arr.fill(8); + + assert.deepEqual(arr, [8,8,8]); + }); + + it('when gets passed an object, it will copy the reference and fill the array with references to that object.', function(){ + const arr = Array(3).fill({}); + //// arr[0].foo = 'bar' + arr[0].hi = "es6 katas"; + + assert.deepEqual(arr[2].hi, 'es6 katas'); + }); + + }); From ab9b7bca24abafc899f2f6376b81264d40f087a4 Mon Sep 17 00:00:00 2001 From: Wolfram Kriesing Date: Wed, 7 Nov 2018 08:29:26 +0800 Subject: [PATCH 2/4] Update katas/es6/language/array-api/fill.js Co-Authored-By: jizusun --- katas/es6/language/array-api/fill.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/es6/language/array-api/fill.js b/katas/es6/language/array-api/fill.js index 9e87cf39..ce6505e2 100644 --- a/katas/es6/language/array-api/fill.js +++ b/katas/es6/language/array-api/fill.js @@ -36,7 +36,7 @@ describe('`Array.prototype.fill` can fill up an array with one value', () => { }); - it('is a mutable method, and will change this object itself', function() { + it('is a mutating method, and will change this object itself', function() { const arr = new Array(3); //// arr.fill('foo') arr.fill(8); From e0fa19558ebf12483b61573716831f4572567a61 Mon Sep 17 00:00:00 2001 From: Jizu Sun Date: Thu, 22 Nov 2018 11:06:04 +0800 Subject: [PATCH 3/4] refactor one kata for Array.fill --- katas/es6/language/array-api/fill.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/katas/es6/language/array-api/fill.js b/katas/es6/language/array-api/fill.js index ce6505e2..74203640 100644 --- a/katas/es6/language/array-api/fill.js +++ b/katas/es6/language/array-api/fill.js @@ -44,12 +44,12 @@ describe('`Array.prototype.fill` can fill up an array with one value', () => { assert.deepEqual(arr, [8,8,8]); }); - it('when gets passed an object, it will copy the reference and fill the array with references to that object.', function(){ - const arr = Array(3).fill({}); - //// arr[0].foo = 'bar' - arr[0].hi = "es6 katas"; + it('when gets passed an object, all elements of the mutated array would be the same reference to that object', function(){ + //// const obj = {hi: 'foobar'}; + const obj = {hi: 'es6 katas'}; + const arr = Array(3).fill(obj); - assert.deepEqual(arr[2].hi, 'es6 katas'); + assert.equal(arr[2].hi, 'es6 katas'); }); From ad9c48f4aae9442574c4b70db9d274ec4c4cf504 Mon Sep 17 00:00:00 2001 From: Jizu Sun Date: Thu, 22 Nov 2018 11:07:58 +0800 Subject: [PATCH 4/4] remove empty lines --- katas/es6/language/array-api/fill.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/katas/es6/language/array-api/fill.js b/katas/es6/language/array-api/fill.js index 74203640..6c2a109d 100644 --- a/katas/es6/language/array-api/fill.js +++ b/katas/es6/language/array-api/fill.js @@ -35,7 +35,6 @@ describe('`Array.prototype.fill` can fill up an array with one value', () => { assert.deepEqual(arr, [1, 42, 3]); }); - it('is a mutating method, and will change this object itself', function() { const arr = new Array(3); //// arr.fill('foo') @@ -51,6 +50,4 @@ describe('`Array.prototype.fill` can fill up an array with one value', () => { assert.equal(arr[2].hi, 'es6 katas'); }); - - });