forked from b00tc4mp/isdi-parttime-202410
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add array & dorraymon prototype.push b00tc4mp#8
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
staff/quique-cabrera/playground/array/Array.prototype.push.test.js
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,54 @@ | ||
console.log('TEST Array.prototype.push') | ||
|
||
console.log('CASE add character to sponge bob characters') | ||
|
||
var chars = new Array | ||
chars[0] = 'Sponge Bob' | ||
chars[1] = 'Patrick Star' | ||
chars[2] = 'Squidward Tentacles' | ||
chars[3] = 'Gary the Snail' | ||
|
||
var length = chars.push('Sheldon Plankton') | ||
|
||
console.log(length) | ||
// 5 | ||
console.log(chars) | ||
// ['Sponge Bob', 'Patrick Star', 'Squidward Tentacles', 'Gary the Snail', 'Sheldon Plankton'] | ||
|
||
var tags = new Array | ||
tags[0] = 'html' | ||
tags[1] = 'head' | ||
tags[2] = 'body' | ||
var length = tags.push('h1', 'p', 'table', 'img', 'video') | ||
console.log(length) | ||
//8 | ||
console.log(tags) | ||
//[ 'html', 'head','body', 'h1', 'p', 'table', 'img', 'video' ] | ||
|
||
console.log('CASE add various arrays into nums') | ||
|
||
var nums = new Array | ||
var length = nums.push([1, 2, 3], [4, 5], [6], [], [7], [8, 9, 10, 11]) | ||
console.log(length) | ||
// 6 | ||
console.log(nums) | ||
// [[1 ,2, 3], [4,5], [6], [], [7], [8, 9, 10, 11]] | ||
console.log(nums[0][2]) | ||
// 3 | ||
var length = nums[0].push(12, 13) | ||
// [1, 2, 3, 12, 13] | ||
console.log(nums.length) | ||
// 6 | ||
console.log(nums) | ||
// [[1, 2, 3, 12, 13], [4,5], [6], [], [7], [8, 9, 10, 11]] | ||
var length = nums[1].push([14, 15, 16]) | ||
console.log(length) | ||
// 3 | ||
console.log(nums[1]) | ||
// [ 4, 5, [ 14, 15, 16 ] ] | ||
console.log(nums.length) | ||
// 6 | ||
console.log(nums) | ||
// [ [ 1, 2, 3, 12, 13 ], [ 4, 5, [ 14, 15, 16 ] ], [ 6 ], [], [ 7 ], [ 8, 9, 10, 11 ]] | ||
console.log(nums[1][2][1]) | ||
// 15 |
41 changes: 41 additions & 0 deletions
41
staff/quique-cabrera/playground/dorraymon/Dorraymon.prototype.push.test.1.js
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,41 @@ | ||
function Dorraymon() { | ||
this.length = 0 | ||
} | ||
|
||
Dorraymon.prototype.push = function (element) { | ||
for (var i = 0; i < arguments.length; i++) { | ||
var argument = arguments[i] | ||
|
||
this[this.length] = element | ||
this.length++ | ||
} | ||
|
||
return this.length | ||
} | ||
|
||
console.log('TEST Dorraymon.prototype.push') | ||
|
||
console.log('CASE add charracter to sponge bob characters') | ||
|
||
var chars = new Dorraymon | ||
chars[0] = 'Sponge Bob' | ||
chars[1] = 'Patrick Star' | ||
chars[2] = 'Squidward Tentacles' | ||
chars[3] = 'Gary the Snail' | ||
chars.length = 4 | ||
var length = chars.push('Sheldon Plankton') | ||
console.log(length) | ||
// 5 | ||
console.log(chars) | ||
// Dorraymon {0: 'Sponge Bob', 1: 'Patrick Star', 2: 'Squidward Tentacles', 3: 'Gary the Snail', 4: 'Sheldon Plankton', length: 5} | ||
|
||
var tags = new Dorraymon | ||
tags[0] = 'html' | ||
tags[1] = 'head' | ||
tags[2] = 'body' | ||
tags.length = 3 | ||
var length = tags.push('h1', 'p', 'table', 'img', 'video') | ||
console.log(length) | ||
//8 | ||
console.log(tags) | ||
// Dorraymon { 0: 'html', 1: 'head', 2:'body', 3:'h1', 4:'p', 5:'table', 6:'img', 7:'video' } |
26 changes: 26 additions & 0 deletions
26
staff/quique-cabrera/playground/dorraymon/Dorraymon.prototype.push.test.js
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,26 @@ | ||
function Dorraymon() { | ||
this.length = 0 | ||
} | ||
|
||
Dorraymon.prototype.push = function (element) { | ||
this[this.length] = element | ||
this.length++ | ||
return this.length | ||
} | ||
|
||
console.log('TEST Dorraymon.prototype.push') | ||
|
||
console.log('CASE add charracter to sponge bob characters') | ||
|
||
var chars = new Dorraymon | ||
chars[0] = 'Sponge Bob' | ||
chars[1] = 'Patrick Star' | ||
chars[2] = 'Squidward Tentacles' | ||
chars[3] = 'Gary the Snail' | ||
chars.length = 4 | ||
var length = chars.push('Sheldon Plankton') | ||
console.log(length) | ||
// 5 | ||
console.log(chars) | ||
// Dorraymon {0: 'Sponge Bob', 1: 'Patrick Star', 2: 'Squidward Tentacles', 3: 'Gary the Snail', 4: 'Sheldon Plankton', length: 5} | ||
|