Skip to content

Commit

Permalink
add changes to Array and Arroz to b00tc4mp#65
Browse files Browse the repository at this point in the history
  • Loading branch information
Thea272 committed Oct 15, 2024
1 parent 3597765 commit e712e8d
Show file tree
Hide file tree
Showing 6 changed files with 477 additions and 0 deletions.
9 changes: 9 additions & 0 deletions staff/tea-kintiraia/playground/array/Array.prototype.pop.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ console.log(cart)
*/
console.log(extracted)
// { brand: 'Puma', size: 44, price: 50 }

// mi ejemplo>>>>>>>
console.log('CASE extract a coat from myCloset')
var myCloset = ['jacket','coat', 'jersey', 'shirt', 'dress']
var extracted = myCloset.pop()
console.log(myCloset)
// ['jacket', 'jersey', 'shirt', 'dress']


20 changes: 20 additions & 0 deletions staff/tea-kintiraia/playground/array/Array.prototype.push.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,23 @@ console.log(chars)
// ["A", "B", "C", "D", "E", "F"] (6)
console.log(length)
// 6

console.log('CASE add many elements in one call')

var colors = ['red', 'green', 'blue', 'magenta']
var length = colors.push('cyan', 'yellow', 'orange', 'pink')
console.log(colors)
//['red', 'green', 'blue', 'magneta', cyian', 'yellow', 'orange', 'pink']
console.log(length)
// 8

//mi ejemplo>>>>>>
console.log('CASE add grapes and onions to shoppingList')
var shoppingList = ['bread', 'butter', 'oranges', 'meat']
var length = shoppingList.push('grapes', 'onions')
console.log(shoppingList)
//['bread', 'butter', 'oranges', 'meat', 'grapes', 'onions']
console.log(length)
// 6


116 changes: 116 additions & 0 deletions staff/tea-kintiraia/playground/arroz/Arroz.prototype.at.1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
var Arroz = function () {this.length = 0 }
/* El metodo 'Asignamos al prototipo de arroz la función de 'index', de buscar el valor de una posición y devolverlo, permitiendo valores positivos y negativos.*/
Arroz.prototype.at = function (index) {
return this[index]
}

console.log('TEST Arroz.prototype.at')

console.log('CASE get element at index 2')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = {a: 1, b: 2, c: 3}
things[4] = null
things[5] = undefined
things[6] = function() {return 'hello world'}
things.length = 7
var element = things.at(2)
console.log(element)
//hola mundo

console.log('CASE get element at index 3')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(3)
console.log(element)
// {a: 1, b: 2, c: 3}

/*
console.log ('CASE get element at offset -1')
var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(-1)
console.log(element)
//function () {return 'hello world'}
console.log(element())
// hello world
console.log('CASE get element at offset -3')
var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(-3)
console.log(element)
//null
conosole.log('CASE get element at 1000')
var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(1000)
console.log(element)
// undefined
console.log('CASE element at -1000')
var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(-1000')
console.log(element)
// undefined
*/

console.log('TEST Arroz.prototype.at')

console.log('CASE get element at -1')

var moovies = new Arroz
moovies[0] = twilight
moovies[1] = sabrina
moovies[3] = casablanca
moovies[4] = grace
moovies.length = 5
var element = moovies.at(1)
console.log(element)
//sabrina
132 changes: 132 additions & 0 deletions staff/tea-kintiraia/playground/arroz/Arroz.prototype.at.2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
var Arroz = function () {this.length = 0 }

Arroz.prototype.at = function (index) {
if (index >= 0)
return this[index]
else
return this[this.length + index]
}

console.log('TEST Arroz.prototype.at')

console.log('CASE get element at index 2')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = {a: 1, b: 2, c: 3}
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world'}
things.length = 7
var element = things.at(2)
console.log(element)
//hola mundo

console.log('CASE get element at index 3')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(3)
console.log(element)
// { a: 1, b: 2, c: 3 }

console.log('CASE get element at offset -1')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(-1)
console.log(element)
//function () {return 'hello world'}
console.log(element())
//hello world

console.log('CASE get element at index -3')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(-3)
console.log(element)
// null

conosole.log('CASE get element at 1000')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(1000)
console.log(element)
// undefined

console.log('CASE element at -1000')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(-1000)
console.log(element)
// undefined

//*mi ejemplo:

console.log('CASE element at 5')

var myFood = new Arroz
myFood[0] = 'chicken';
myFood[1] = 'butter';
myFood[2] = 'vegetables';
myFood[3] = 'fruits';
myFood[4] = 'pasta';
myFood[5] = function () { return 'hello world' }
myFood.length = 6
var element = myFood.at (5)
console.log(element)
// function () { return 'hello world'}

console.log('CASE element at -2')

var myFood = new Arroz
myFood[0] = 'chicken';
myFood[1] = 'butter';
myFood[2] = 'vegetables';
myFood[3] = 'fruits';
myFood[4] = 'pasta';
myFood[5] = function () { return 'hello world' }
myFood.length = 6
var element = myFood.at(-2)
console.log(element)
// 'pasta'
102 changes: 102 additions & 0 deletions staff/tea-kintiraia/playground/arroz/Arroz.prototype.at.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
var Arroz = function () { this.length = 0 }

Arroz.prototype.at = function (index) {
if (index > -1) // index > -1
return this[index]
else
return this[this.length + index]
}

console.log('TEST Arroz.prototype.at')

console.log('CASE get element at index 2')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = {a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world'}
things.length = 7
var element = things.at(2)
console.log(element)
//hola mundo

console.log('CASE get element at index 3')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(3)
console.log(element)
// { a: 1, b: 2, c: 3 }

console.log('CASE get element at offset -1')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(-1)
console.log(element)
// function () { return 'hello world'}
console.log(element())
// hello world

console.log('CASE get element at offset -3')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(-3)
console.log(element)
//null

console.log('CASE get element at 1000')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(1000)
console.log(element)
//undefined

console.log('CASE get element at -1000')

var things = new Arroz
things[0] = 100
things[1] = true
things[2] = 'hola mundo'
things[3] = { a: 1, b: 2, c: 3 }
things[4] = null
things[5] = undefined
things[6] = function () { return 'hello world' }
things.length = 7
var element = things.at(-1000)
console.log(element)
//undefined
Loading

0 comments on commit e712e8d

Please sign in to comment.