File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
javascript-today-magazine Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 2
2
JavaScript Today Magazine
3
3
short: JavaScriptTM
4
4
[JavaScriptTM] Bubble Sort
5
-
5
+ [DataStructuresAlgorithms]
6
6
17.09.2022: Some common algorithms implemented in JavaScript: Bubble Sort, Selection Sort, and Merge Sort.
7
7
1. Bubble Sort
8
8
2. Selection Sort
Original file line number Diff line number Diff line change
1
+ /**
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.
4
+ * Rather than using built-in methods like ".reverse()" (which is fine, but you may be asked to neglect using it), 👍
5
+ * demonstrate your ability to solve it in different ways.
6
+ *
7
+ * Here are three solutions to reversing a string in JavaScript.👏
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
+ }
You can’t perform that action at this time.
0 commit comments