Skip to content

Commit caa69c6

Browse files
committed
Function #25: & #26: Added
1 parent 24bf155 commit caa69c6

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

Problem.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
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

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff 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();
333333
console.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+
```

script.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff 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
215215
const arr = [1, 2, 3];
216216
arr.reverse();
217217
console.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);

0 commit comments

Comments
 (0)