Skip to content

Commit 5cbf128

Browse files
reversed string using stack
1 parent cc8cbe1 commit 5cbf128

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

daily-dsa/6.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//reverseString
2+
3+
function solution(str) {
4+
let stack = [];
5+
for (let i = 0; i < str.length; i++) {
6+
stack.push(str[i]);
7+
}
8+
let reversed = "";
9+
while (stack.length > 0) {
10+
reversed += stack.pop();
11+
}
12+
return reversed;
13+
}
14+
const res = solution("hello");
15+
console.log(res);

0 commit comments

Comments
 (0)