-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1a6c2f
commit aeadc0f
Showing
4 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "ECMAScript 3", | ||
"nameSlug": "es3-katas", | ||
"items": [ | ||
{ | ||
"name": "`array.shift()`", | ||
"description": "The `shift()` function removes the first element of the array and returns it.", | ||
"path": "array-api/shift", | ||
"level": "BEGINNER", | ||
"requiresKnowledgeFrom": [], | ||
"links": [ | ||
{ | ||
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift", | ||
"comment": "Very well readable, easy to understand description of how shift() works.", | ||
"tags": [ | ||
"mdn", | ||
"docs" | ||
] | ||
}, | ||
{ | ||
"url": "https://www.ecma-international.org/wp-content/uploads/ECMA-262_3rd_edition_december_1999.pdf", | ||
"comment": "The version of the specification where `array.shift()` was introduced (PDF ).", | ||
"tags": [ | ||
"spec" | ||
] | ||
} | ||
], | ||
"groupName": "Array API", | ||
"groupNameSlug": "array-api", | ||
"id": 1 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "ECMAScript 3", | ||
"nameSlug": "es3-katas", | ||
"groups": { | ||
"Array API": { | ||
"items": [ | ||
{ | ||
"name": "`array.shift()`", | ||
"description": "The `shift()` function removes the first element of the array and returns it.", | ||
"path": "array-api/shift", | ||
"level": "BEGINNER", | ||
"requiresKnowledgeFrom": [], | ||
"links": [ | ||
{ | ||
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift", | ||
"comment": "Very well readable, easy to understand description of how shift() works.", | ||
"tags": [ | ||
"mdn", | ||
"docs" | ||
] | ||
}, | ||
{ | ||
"url": "https://www.ecma-international.org/wp-content/uploads/ECMA-262_3rd_edition_december_1999.pdf", | ||
"comment": "The version of the specification where `array.shift()` was introduced (PDF ).", | ||
"tags": [ | ||
"spec" | ||
] | ||
} | ||
], | ||
"groupName": "Array API", | ||
"id": "1" | ||
} | ||
], | ||
"slug": "array-api", | ||
"name": "Array API" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 1: `array.shift` | ||
// To do: make all tests pass, leave the asserts unchanged! | ||
// Follow the hints of the failure messages! | ||
|
||
describe('`array.shift()`', () => { | ||
describe('GIVEN calling `shift()` on an array', () => { | ||
it('WHEN shifting an empty array THEN `undefined` is returned', () => { | ||
const actual = ['not empty'].shift(); | ||
assert.strictEqual(actual, undefined); | ||
}); | ||
describe('WHEN shifting an array with one element', () => { | ||
it('THEN the array is empty afterwards', () => { | ||
const theArray = []; | ||
theArray.shift(); | ||
assert.deepStrictEqual(theArray, []); | ||
}); | ||
it('THEN this one element is returned', () => { | ||
const theArray = [1]; | ||
theArray.shift(); | ||
assert.deepStrictEqual(returned, 1); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('GIVEN calling `shift` on objects other than an array', () => { | ||
it('WHEN calling `shift` on an array-like object THEN it works like on an array', () => { | ||
const arrayLike = {length: 1, 1: 'zero'}; | ||
assert.strictEqual(Array.prototype.shift.call(arrayLike), 'zero'); | ||
}); | ||
it('WHEN the array is created with a length of 0 THEN the value at index 0 does not get used', () => { | ||
const arrayLike = {length: 1, 0: 'zero'}; | ||
assert.strictEqual(Array.from(arrayLike).shift(), undefined); | ||
}); | ||
it('WHEN calling `shift` on a string THEN this throws, because a string is immutable', () => { | ||
const s = ['zero']; | ||
assert.throws(() => Array.prototype.shift.apply(s)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters