Skip to content

Commit 39c1c99

Browse files
committedAug 14, 2020
Arrays: Basics Complete (#2 IP)
Created ATLA-themed JS array example
1 parent 4e76e24 commit 39c1c99

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
 

‎Data-Structures/Arrays/Basics.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: deno run Data-Structures/Arrays/Basics.ts
2+
3+
4+
const teamAvatar = ['Aang','Appa','Momo','Katara','Sokka'];
5+
6+
// Push adds an element to the end of the array
7+
teamAvatar.push('Yue'); // O(1)
8+
9+
// Pop removes and returns the last element
10+
console.log(teamAvatar.pop(), 'turned into the moon!!!'); // O(1)
11+
console.log(teamAvatar.pop(), "is in disbelief..."); // O(1)
12+
13+
console.log(teamAvatar);
14+
15+
console.log('Team Avatar is', teamAvatar.push('Sokka'), 'strong.');
16+
17+
// Unshift adds the specified elements to the beginning of the array
18+
teamAvatar.unshift('Toph'); // O(n)
19+
20+
console.log('Toph joins the team!');
21+
22+
// Splice(i, n) removes n elements starting from index i
23+
teamAvatar.splice(2, 1); // O(n)
24+
25+
console.log('Appa was captured?!?!', teamAvatar);
26+
27+
// Splice(i, 0, [elements]) inserts [elements] at index i
28+
teamAvatar.splice(2, 0, 'Appa'); // O(n)
29+
30+
console.log('Zuko saved Appa!!!', teamAvatar);

‎deps.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// ----------------------- Standard Library -----------------------
2+
3+
4+
// ---------------------- Third-Party Modules ----------------------

0 commit comments

Comments
 (0)