Skip to content

Commit

Permalink
Move data structs to a separate dir and create algorithms dir
Browse files Browse the repository at this point in the history
Signed-off-by: Darko Draskovic <[email protected]>
  • Loading branch information
darkodraskovic committed Feb 17, 2022
1 parent 4fb4f55 commit c4eaae7
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/algorithms/recursion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 1. identify base case
// 2. identify recursion case
// 3. usually, there are 2 returns, one for each case
// function gets closer and closers to the base case
function inception(counter) {
if (counter < 0) {
return 'done';
}
return inception(--counter);
}

export function test() {
console.log(inception(3));
}
10 changes: 5 additions & 5 deletions src/array.js → src/data-structures/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class MyArray {
}

pop() {
const lastItem = this.data[this.length-1];
delete this.data[this.length-1];
const lastItem = this.data[this.length - 1];
delete this.data[this.length - 1];
this.length--;
return lastItem;
}
Expand All @@ -29,10 +29,10 @@ export class MyArray {
}

shiftItems(index) {
for (let i = index; i < this.length-1; i++) {
this.data[i] = this.data[i+1];
for (let i = index; i < this.length - 1; i++) {
this.data[i] = this.data[i + 1];
}
delete this.data[this.length-1];
delete this.data[this.length - 1];
}
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { test } from './graph.js'
import { test } from './algorithms/recursion.js'

test();

0 comments on commit c4eaae7

Please sign in to comment.