Skip to content

Commit

Permalink
add all arrays method b00tc4mp#8
Browse files Browse the repository at this point in the history
  • Loading branch information
frameloop committed Oct 23, 2024
1 parent f31d91f commit 67f8497
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
console.log('TEST Array.prototype.concat')

console.log('CASE merge two arrays')

var sea = new Array
sea[0] = 'shark'
sea[1] = 'octopus'
sea[2] = 'Sponge'
sea[3] = 'Whale'
console.log(sea)
//[ 'shark', 'octopus', 'Sponge', 'Whale' ]
console.log(sea.length)
4

var land = new Array
land[0] = 'elephant'
land[1] = 'bear'
land[2] = 'fox'
land[3] = 'lion'
console.log(land)
//[ 'elephant', 'bear', 'fox', 'lion' ]
console.log(land.length)
//4

var forest = new Array
forest[0] = 'elephant'
forest[1] = 'bear'
forest[2] = 'fox'
forest[3] = 'lion'
var sky = new Array
sky[0] = 'crow'
sky[1] = 'eagle'
sky[2] = 'sparow'
sky[3] = 'duck'
console.log(sky)
//[ 'crow', 'eagle', 'sparow', 'duck' ]
console.log(sky.length)
//4

var animals = sea.concat(forest);
console.log('CASE 1 merge two animals class')

var animals = sea.concat(land);
console.log(animals)
//[ 'shark', 'octopus', 'Sponge', 'Whale', 'elephant', 'bear', 'fox', 'lion' ]
console.log(animals.length)
//8

console.log('CASE 2 merge three animals class')

var wildLife = sea.concat(land, sky)
console.log(wildLife)
//['shark', 'octopus', 'Sponge', 'Whale', 'elephant', 'bear', 'fox', 'lion', 'crow', 'eagle', 'sparow', 'duck']
console.log(wildLife.length)
//12

console.log('CASE 3 merge three animals class and string')
var party = sea.concat(land, sky, ' are going to party!')
console.log(party)
//['shark', 'octopus', 'Sponge', 'Whale', 'elephant', 'bear', 'fox', 'lion', 'crow', 'eagle', 'sparow', 'duck', ' are going to party!']
console.log(party.length)
//13
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ motoGp[3] = 'Maverick Viñales'
motoGp[4] = 'Joan Mir'
motoGp[5] = 'Pol Espargaró'
motoGp[6] = 'Dani Pedrosa'

console.log(motoGp.includes('Maverick Viñales'))
//true

console.log(motoGp.includes('Valentino Rossi'))
//false
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
console.log('TEST Array.prototype.lastIndexOf')

console.log('CASE 1 returns the index of second groundhog')

var frase = 'The goose saw the groundhog, but the groundhog went away'

console.log(frase.lastIndexOf('groundhog'))
//37
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ part[2] = 'exhaust pipe'
part[3] = 'battery'
part[4] = 'carburator'
part[5] = 'tomato'

var fruit = part.pop()

console.log(part)
console.log(fruit)
//['cylinder', 'air filter', 'exhaust pipe', 'battery', 'carburator']
console.log(fruit)
//tomato


19 changes: 19 additions & 0 deletions staff/quique-cabrera/playground/array/Array.prototype.reverse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
console.log('TEST Array.prototype.reverse')

console.log('CASE reverse array order')

var elements = new Array
elements[0] = 'H2O'
elements[1] = 'CO2'
elements[2] = 'NO2'
elements[3] = 'CU2S'

console.log('elements:', elements)
//elements: [ 'H2O', 'CO2', 'NO2', 'CU2S' ]

var newOrder = elements.reverse()
console.log('New Order', newOrder)
//New Order [ 'CU2S', 'NO2', 'CO2', 'H2O' ]

console.log('elements:', elements)
//New Order [ 'CU2S', 'NO2', 'CO2', 'H2O' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function Dorraymon() {
this.length = 0
}

Dorraymon.prototype.concat = function (element) {
for (var i = 0; i < this.length; i++) {
result = this[i]
result.length++
}

return this.length
}
Empty file.
Empty file.
Empty file.

0 comments on commit 67f8497

Please sign in to comment.