Files

51 lines
1001 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Apply Functional Programming to Convert Strings to URL Slugs
---
# Apply Functional Programming to Convert Strings to URL Slugs
2018-10-12 15:37:13 -04:00
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
2018-10-12 15:37:13 -04:00
```javascript
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
return title
.split(/\W/)
.filter(obj => {
return obj !== "";
})
.join("-")
.toLowerCase();
2018-10-12 15:37:13 -04:00
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
```
</details>
2018-10-12 15:37:13 -04:00
<details><summary>Solution 2 (Click to Show/Hide)</summary>
2018-10-12 15:37:13 -04:00
```javascript
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
return title
.toLowerCase()
.trim()
.split(/\s+/)
.join("-");
2018-10-12 15:37:13 -04:00
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
```
</details>