Skip to content

Commit 04f3625

Browse files
problem-23.js solved
1 parent 96da67f commit 04f3625

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
| Problem - 20 | Detect device types |
2525
| Problem - 21 | Return the total of all the records' scores - GameOf11 |
2626
| Problem - 22 | Check the number is Palindrome or not |
27+
| Problem - 23 | Create a function that receives a string "abcbdbd", and returns an array like: ["a", "a.b", "a.b.c", "a.b.c.b", "a.b.c.b.d", "a.b.c.b.d.b", ...] |
2728
<!-- | Problem - 22 | | -->

Diff for: problem-23.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Let us create a function that receives a string "abcbdbd",
3+
* and returns an array like:
4+
["a", "a.b", "a.b.c", "a.b.c.b", "a.b.c.b.d", "a.b.c.b.d.b", ...]
5+
*/
6+
7+
const str = 'abcbdbd';
8+
9+
function splitString(str) {
10+
const arr = str.split('');
11+
let tempArr = [];
12+
13+
for (let i = 1; i < arr.length; i++) {
14+
let cutArray = arr.slice(0, i).join('.');
15+
tempArr.push(cutArray);
16+
}
17+
18+
return tempArr;
19+
}
20+
21+
console.log(splitString(str));

0 commit comments

Comments
 (0)