Skip to content

Commit 251b2db

Browse files
committed
Complete spinal tap case
1 parent 27ea256 commit 251b2db

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/fcc-intermediate-algorithms/fcc-intermediate-algorithms.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ From the Freecodecamp Javascript Certification Intermediate Algorithms module
88
- [Diff Two Arrays](#diff-two-arrays)
99
- [Seek and Destroy](#seek-and-destroy)
1010
- [Wherefore Art Thou](#wherefore-art-thou)
11+
- [Spinal Tap Case](#spinal-tap-case)
1112

1213
#### Sum All Numbers In a Range
1314

@@ -69,3 +70,13 @@ export function whatIsInAName(collection, source) {
6970
});
7071
}
7172
```
73+
74+
#### Spinal Tap Case
75+
76+
Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
77+
78+
```javascript
79+
export function spinalCase(str) {
80+
return str.split(/[_\W]|(?=[A-Z])/).join('-').toLowerCase();
81+
}
82+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function spinalCase(str) {
2+
return str.split(/[_\W]|(?=[A-Z])/).join('-').toLowerCase();
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { spinalCase } from "../../src/fcc-intermediate-algorithms/spinal_tap_case";
2+
3+
test('should join all words as lower case seperated by dashes', () => {
4+
let str = "this_Is SpinalTap"
5+
expect(spinalCase(str)).toBe("this-is-spinal-tap");
6+
expect(str).toBe("this_Is SpinalTap");
7+
});

0 commit comments

Comments
 (0)