forked from b00tc4mp/isdi-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.
- Loading branch information
1 parent
6851e53
commit da13321
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
staff/manuel-barzi/playground/arrays/Array.prototype.pop.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,21 @@ | ||
console.log('TEST Array.prototype.pop') | ||
|
||
console.log('CASE extract tomato from veggies') | ||
|
||
var veggies = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'] | ||
var veggie = veggies.pop() | ||
|
||
console.log(veggies) | ||
// ['broccoli', 'cauliflower', 'cabbage', 'kale'] | ||
console.log(veggie) | ||
// tomato | ||
|
||
console.log('CASE extract yellow from colors') | ||
|
||
var colors = ['red', 'green', 'blue', 'yellow'] | ||
var color = colors.pop() | ||
|
||
console.log(colors) | ||
// ['red', 'green', 'blue'] | ||
console.log(color) | ||
// yellow |
21 changes: 21 additions & 0 deletions
21
staff/manuel-barzi/playground/arrays/Array.prototype.push.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,21 @@ | ||
console.log('TEST Array.prototype.push') | ||
|
||
console.log('CASE add 400 to nums') | ||
|
||
var nums = [100, 200, 300] | ||
var length = nums.push(400) | ||
|
||
console.log(nums) | ||
// [100, 200, 300, 400] (4) | ||
console.log(length) | ||
// 4 | ||
|
||
console.log('CASE add banana to fruits') | ||
|
||
var fruits = ['apple', 'orange', 'raspberry', 'pineapple'] | ||
var length = fruits.push('banana') | ||
|
||
console.log(fruits) | ||
// ['apple', 'orange', 'raspberry', 'pineapple', 'banana'] (5) | ||
console.log(length) | ||
// 5 |
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,36 @@ | ||
var pop = function (iterable) { | ||
/* | ||
extract last element from iterable | ||
descrease length from iterable | ||
delete last element from iterable | ||
return extracted element | ||
*/ | ||
|
||
var last = iterable[iterable.length - 1] | ||
|
||
delete iterable[iterable.length - 1] | ||
|
||
iterable.length-- | ||
|
||
return last | ||
} | ||
|
||
console.log('CASE extract tomato from veggies') | ||
|
||
var veggies = { 0: 'broccoli', 1: 'cauliflower', 2: 'cabbage', 3: 'kale', 4: 'tomato', length: 5 } | ||
var veggie = pop(veggies) | ||
|
||
console.log(veggies) | ||
// { 0: 'broccoli', 1: 'cauliflower', 2: 'cabbage', 3: 'kale', length: 4 } | ||
console.log(veggie) | ||
// tomato | ||
|
||
console.log('CASE extract yellow from colors') | ||
|
||
var colors = { 0: 'red', 1: 'green', 2: 'blue', 3: 'yellow', length: 4 } | ||
var color = pop(colors) | ||
|
||
console.log(colors) | ||
// { 0: 'red', 1: 'green', 2: 'blue', length: 3 } | ||
console.log(color) | ||
// yellow |
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,28 @@ | ||
var push = function (iterable, element) { | ||
iterable[iterable.length] = element | ||
iterable.length++ | ||
|
||
return iterable.length | ||
} | ||
|
||
console.log('TEST push') | ||
|
||
console.log('CASE add 400 to nums') | ||
|
||
var nums = { 0: 100, 1: 200, 2: 300, length: 3 } | ||
var length = push(nums, 400) | ||
|
||
console.log(nums) | ||
// { 0: 100, 1: 200, 2: 300, 3: 400, length: 4 } | ||
console.log(length) | ||
// 4 | ||
|
||
console.log('CASE add banana to fruits') | ||
|
||
var fruits = { 0: 'apple', 1: 'orange', 2: 'raspberry', 3: 'pineapple', length: 4 } | ||
var length = push(fruits, 'banana') | ||
|
||
console.log(fruits) | ||
// { 0: 'apple', 1: 'orange', 2: 'raspberry', 3: 'pineapple', 4: 'banana', length: 5 } | ||
console.log(length) | ||
// 5 |