Skip to content

Commit 381da7f

Browse files
author
Wakidur Rahaman
committed
modify file
1 parent d409f9d commit 381da7f

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

javascript-today-magazine/note.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
JavaScript Today Magazine
33
short: JavaScriptTM
44
[JavaScriptTM] Bubble Sort
5-
5+
[DataStructuresAlgorithms]
66
17.09.2022: Some common algorithms implemented in JavaScript: Bubble Sort, Selection Sort, and Merge Sort.
77
1. Bubble Sort
88
2. Selection Sort
Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
/**
2-
* Reverse a string. It's a common interview question, and it's quite simple.
3-
* However, if you really want to impress your interviewer, you'd be well-off to understand multiple solutions to the problem.
2+
* Reverse a string. It's a common interview question, and it's quite simple.
3+
* However, if you really want to impress your interviewer, you'd be well-off to understand multiple solutions to the problem.
44
* Rather than using built-in methods like ".reverse()" (which is fine, but you may be asked to neglect using it), 👍
55
* demonstrate your ability to solve it in different ways.
6-
*
6+
*
77
* Here are three solutions to reversing a string in JavaScript.👏
8-
*/
8+
*
9+
*
10+
* Directions
11+
* Given a string, return a new string with the reversed order of characters
12+
*/
13+
14+
// Solution 1:
15+
16+
function reverseStringSolutionOne(str: string) {
17+
return str.split("").reverse().join("");
18+
}
19+
20+
// Solution 2:
21+
22+
function reverseStringSolutionTwo(str: string) {
23+
let reversed: string = "";
24+
for (let character of str) {
25+
reversed = character + reversed;
26+
}
27+
return reversed;
28+
}
29+
30+
// Solution 3:
31+
32+
function reverseStringSolutionThree(str: string) {
33+
return str.split("").reduce((rev, char) => char + rev, "");
34+
}

0 commit comments

Comments
 (0)