We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 57d30d4 commit 1a6949cCopy full SHA for 1a6949c
algorithms/reverse_words.js
@@ -0,0 +1,39 @@
1
+/*
2
+
3
+ Reverse each word of string and return new string
4
+ Don't reverse the whole string just each word separately.
5
+ Don't use array reverse() function
6
7
+*/
8
9
+function reverseWords(str){
10
11
+ let strArr = str.split(" ");
12
13
+ for (let i=0; i < strArr.length; i++) {
14
15
+ const word = strArr[i];
16
+ let reverseWord = "";
17
18
+ for ( let j=word.length - 1; j >= 0; j--) {
19
+ reverseWord += word[j];
20
+ }
21
22
+ /*
23
+ OR
24
25
+ for ( let j=0; j < word.length; j++) {
26
+ reverseWord += word[word.length - (j+1)];
27
28
+ */
29
30
31
+ strArr[i] = reverseWord;
32
33
+ };
34
35
+ return strArr.join(" ");
36
+}
37
38
39
+reverseWords('i am here');
0 commit comments