Skip to content

Commit 92fb69e

Browse files
author
Axel
committed
Add exercise 17
1 parent 66de9c1 commit 92fb69e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var gulp = require('gulp'),
2+
browserSync = require('browser-sync').create();
3+
4+
gulp.task('server', function() {
5+
6+
browserSync.init({
7+
server: "./",
8+
open: false
9+
});
10+
11+
gulp.watch("./*.html").on('change', browserSync.reload);
12+
});
13+
14+
gulp.task('default', ['server']);

17 - Sort Without Articles/index.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Sort Without Articles</title>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
7+
</head>
8+
<body>
9+
<ul id="bands"></ul>
10+
11+
<script>
12+
13+
const bands = ['The Plot in You', 'The Devil Wears Prada', 'Pierce the Veil', 'Norma Jean', 'The Bled', 'Say Anything', 'The Midway State', 'We Came as Romans', 'Counterparts', 'Oh, Sleeper', 'A Skylit Drive', 'Anywhere But Here', 'An Old Dog', 'Rush'];
14+
15+
16+
const strip = (bandName) => bandName.replace(/^(a\s|the\s|an\s)/i, '').trim(); //remove 'a', 'the' and 'an'.
17+
const sortedBands = bands.sort((a, b) => strip(a) > strip(b) ? 1 : -1); //sort alphabetically comparing the bands without articles
18+
19+
const render = sortedBands.map(band => `<li>${band}</li>`).join("");
20+
document.querySelector("#bands").insertAdjacentHTML("beforeend", render);
21+
22+
</script>
23+
24+
</body>
25+
</html>

0 commit comments

Comments
 (0)