Skip to content

Commit 991a393

Browse files
reverse string javascript program
1 parent 2160d21 commit 991a393

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ReverseString.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,24 @@
1616

1717
<script>
1818

19-
const reverseString = str => [...str].reverse().join("");
19+
// method1
20+
// const reverseString = str => [...str].reverse().join("");
2021

22+
// method 2
2123
// const reverseString = (str) => {
2224
// return [...str].reverse().join("");
2325
// }
2426

27+
function reverseString(str) {
28+
let result = "";
29+
30+
for(let i = str.length - 1; i >= 0; i--){
31+
result += str[i]
32+
}
33+
34+
return result;
35+
}
36+
2537
console.log(reverseString("javascript"));
2638
</script>
2739
</html>

0 commit comments

Comments
 (0)