File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed
Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 2222#22: Rotate an array to the left 1 position
2323#23: Reverse an array with createed function, don`t Change orginal array
2424#24: Reverse an array with JavaScript Builtin Method
25+ #25: Reverse a string with createed function, don`t Change orginal string
26+ #26: Reverse a string with JavaScript Builtin Method
2527
2628
2729
Original file line number Diff line number Diff line change @@ -324,7 +324,7 @@ return newArr;
324324
325325```
326326
327- ** // #24 : Reverse an array with JavaScript Builtin Method**
327+ ** #24 : Reverse an array with JavaScript Builtin Method**
328328
329329```
330330
@@ -333,3 +333,32 @@ arr.reverse();
333333console.log(arr);
334334
335335```
336+
337+ ** #25 : Reverse a string with createed function, don`t Change orginal string**
338+
339+ ```
340+
341+ const str = "Md Nazmul Islam";
342+
343+ const newStr = reverseString(str);
344+ console.log(newStr);
345+
346+ function reverseString(str) {
347+ let newStr = "";
348+ for (let i = str.length - 1; i >= 0; i--) {
349+ newStr += str[i];
350+ }
351+ return newStr;
352+ }
353+
354+ ```
355+
356+ ** #26 : Reverse a string with JavaScript Builtin Method**
357+
358+ ```
359+
360+ const str = "Md Nazmul islam";
361+ const newStr = str.split("").reverse().join("");
362+ console.log(newStr);
363+
364+ ```
Original file line number Diff line number Diff line change @@ -209,9 +209,30 @@ function reverseArr(arr) {
209209 }
210210 return newArr;
211211}
212- */
212+
213213
214214// #24: Reverse an array with JavaScript Builtin Method
215215const arr = [1, 2, 3];
216216arr.reverse();
217217console.log(arr);
218+
219+ */
220+
221+ // #25: Reverse a string with createed function, don`t Change orginal string
222+ const str = "Md Nazmul Islam" ;
223+
224+ const newStr = reverseString ( str ) ;
225+ console . log ( newStr ) ;
226+
227+ function reverseString ( str ) {
228+ let newStr = "" ;
229+ for ( let i = str . length - 1 ; i >= 0 ; i -- ) {
230+ newStr += str [ i ] ;
231+ }
232+ return newStr ;
233+ }
234+
235+ // #26: Reverse a string with JavaScript Builtin Method
236+ const str = "Md Nazmul islam" ;
237+ const newStr = str . split ( "" ) . reverse ( ) . join ( "" ) ;
238+ console . log ( newStr ) ;
You can’t perform that action at this time.
0 commit comments