Skip to content

Commit

Permalink
Implement map b00tc4mp#391
Browse files Browse the repository at this point in the history
  • Loading branch information
PereHDZ committed Mar 4, 2024
1 parent 249e3b5 commit 9bd4b6a
Show file tree
Hide file tree
Showing 2 changed files with 310 additions and 207 deletions.
47 changes: 29 additions & 18 deletions staff/pere-hernandez/prototype/arroz/Arroz.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ function Arroz() {
}
}

Arroz.prototype.push = function(){
for (var i = 0; i < arguments.length; i++){
this[this.length] = arguments[i]
this.length++
}
return this.length
}

Arroz.prototype.pop = function(){
var popped = this[this.length - 1]
delete this[this.length - 1]
this.length--
return popped
}

Arroz.prototype.at = function(index){
if (index > -1 && index < this.length){
return this[index]
Expand Down Expand Up @@ -111,13 +96,14 @@ Arroz.prototype.findIndex = function(callback){

// from WIP

/*Arroz.prototype.from = function(element){
Arroz.from = function(element){
var returnedArroz = new Arroz()
for (var i = 0; i < element.length; i++){
newArroz.push(element[i])
returnedArroz[returnedArroz.length] = (element[i])
returnedArroz.length++
}
return returnedArroz
}*/
}

Arroz.prototype.includes = function(){
if (arguments.length === 1){
Expand Down Expand Up @@ -198,6 +184,31 @@ Arroz.prototype.lastIndexOf = function(value, index){
return -1
}

Arroz.prototype.map = function(callback) {
var returnedArroz = new Arroz()
for (var i = 0; i < this.length; i++){
returnedArroz[returnedArroz.length] = (callback(this[i]))
returnedArroz.length++
}

return returnedArroz
}

Arroz.prototype.pop = function(){
var popped = this[this.length - 1]
delete this[this.length - 1]
this.length--
return popped
}

Arroz.prototype.push = function(){
for (var i = 0; i < arguments.length; i++){
this[this.length] = arguments[i]
this.length++
}
return this.length
}

Arroz.prototype.toString = function() {
var string = 'Arroz ['

Expand Down
Loading

0 comments on commit 9bd4b6a

Please sign in to comment.