forked from b00tc4mp/eurofirms-bootcamp-202409
-
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 changes to Array and Arroz to b00tc4mp#65
- Loading branch information
Showing
6 changed files
with
477 additions
and
0 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
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
116 changes: 116 additions & 0 deletions
116
staff/tea-kintiraia/playground/arroz/Arroz.prototype.at.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,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
132
staff/tea-kintiraia/playground/arroz/Arroz.prototype.at.2.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,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
102
staff/tea-kintiraia/playground/arroz/Arroz.prototype.at.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,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 |
Oops, something went wrong.