Skip to content

Commit b45dcc0

Browse files
add: filling-all-the-missed-angle-brackets
1 parent 8ade38b commit b45dcc0

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# JavaScript Assessments
22

3+
- [Filling all the missed angle brackets](filling-all-the-missed-angle-brackets)
34
- [Finding all the anagrams](finding-all-the-anagrams)
45
- [Finding the maximum depth of a binary tree](finding-the-maximum-depth-of-a-binary-tree)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Filling all the missed angle brackets
2+
3+
e.g.:
4+
5+
Input
6+
7+
```console
8+
><<><
9+
```
10+
11+
Output
12+
13+
```console
14+
<>><<><>>
15+
```
16+
17+
## Execute
18+
19+
```bash
20+
node solution.js
21+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const solution = (angles) => {
2+
let missedAngles = angles;
3+
while (/<>/.test(missedAngles)) {
4+
missedAngles = missedAngles.replace(/<>/g, '');
5+
}
6+
const missedOpens = missedAngles.replace(/</g, '').length;
7+
const missedCloses = missedAngles.replace(
8+
/>/g,
9+
'',
10+
).length;
11+
return `${'<'.repeat(missedOpens)}${angles}${'>'.repeat(
12+
missedCloses,
13+
)}`;
14+
};
15+
16+
(() => {
17+
console.log(solution('><<><'));
18+
})();

0 commit comments

Comments
 (0)