Skip to content

Commit

Permalink
add array & dorraymon prototype.push b00tc4mp#8
Browse files Browse the repository at this point in the history
  • Loading branch information
frameloop committed Oct 20, 2024
1 parent 90fa5a8 commit a2eb790
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
54 changes: 54 additions & 0 deletions staff/quique-cabrera/playground/array/Array.prototype.push.test.js
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
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' }
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}

0 comments on commit a2eb790

Please sign in to comment.