Skip to content

Commit 6438d24

Browse files
author
Connor Leech
committed
add steps recursive solution
1 parent 79a94d1 commit 6438d24

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

udemy-interview-bootcamp-course/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ Udemy course link: [The Coding Interview Bootcamp: Algorithms + Data Structures]
55

66
[Source code](https://github.com/StephenGrider/algocasts) for the lessons.
77

8+
## Additional Resources
9+
10+
### Regular Expressions
11+
12+
- An Introduction to Regular Expressions (Regex) In JavaScript ([Medium article](https://codeburst.io/an-introduction-to-regular-expressions-regex-in-javascript-1d3559e7ac9a))
13+
14+
- Chapter 9: Regular Expressions ([Eloquent Javascript](https://eloquentjavascript.net/09_regexp.html))
15+
16+
- Regular Expressions ([Javascript.info](https://javascript.info/regular-expressions))
17+

udemy-interview-bootcamp-course/steps.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,39 @@
2020

2121
function steps(size){
2222

23-
for(let i = 0; i < size; i++){
24-
let row = '';
23+
for(let row = 0; row < size; row++){
24+
let step = '';
2525

26-
for(let j = 0; j < size; j++){
27-
if(i >= j){
28-
row += '#';
26+
for(let column = 0; column < size; column++){
27+
if(row >= column){
28+
step += '#';
2929
} else {
30-
row += ' ';
30+
step += ' ';
3131
}
3232

3333
}
34-
console.log(row);
34+
console.log(step);
3535
}
3636
}
3737

38-
steps(4);
38+
function stepsRecursive(size, row = 0, step = ''){
39+
// base case
40+
if(size === row){
41+
return;
42+
}
43+
44+
// move on to next row
45+
if(size === step.length){
46+
console.log(step);
47+
return stepsRecursive(size, row + 1);
48+
}
49+
50+
// build current row
51+
step += (step.length <= row) ? '#' : ' ';
52+
53+
stepsRecursive(size, row, step);
54+
}
55+
56+
stepsRecursive(4);
57+
58+

0 commit comments

Comments
 (0)