Skip to content

Commit a0ba69c

Browse files
committedApr 25, 2017
Isogram solution
1 parent 3d18514 commit a0ba69c

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
 

‎isogram/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Isogram
2+
3+
Determine if a word or phrase is an isogram.
4+
5+
An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter.
6+
7+
Examples of isograms:
8+
9+
- lumberjacks
10+
- background
11+
- downstream
12+
13+
The word *isograms*, however, is not an isogram, because the s repeats.
14+
15+
## Setup
16+
17+
Go through the setup instructions for JavaScript to
18+
install the necessary dependencies:
19+
20+
http://exercism.io/languages/javascript
21+
22+
## Making the Test Suite Pass
23+
24+
Execute the tests with:
25+
26+
jasmine-node .
27+
28+
In many test suites all but the first test have been skipped.
29+
30+
Once you get a test passing, you can unskip the next one by
31+
changing `xit` to `it`.
32+
33+
## Source
34+
35+
Wikipedia [https://en.wikipedia.org/wiki/Isogram](https://en.wikipedia.org/wiki/Isogram)
36+
37+
## Submitting Incomplete Problems
38+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
39+

‎isogram/isogram.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const Isogram = function (input) {
2+
this.value = input.toLowerCase();
3+
};
4+
5+
const notRemovable = /[-\s]/;
6+
7+
Isogram.prototype.isIsogram = function () {
8+
const chars = Array
9+
.from(this.value)
10+
.reduce((acc, char) => {
11+
if (acc.indexOf(char) === -1 || notRemovable.test(char)) {
12+
return acc + char;
13+
} else {
14+
return acc
15+
}
16+
});
17+
18+
return chars === this.value;
19+
};
20+
21+
module.exports = Isogram;

‎isogram/isogram.spec.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
var Isogram = require('./isogram');
2+
3+
describe('Isogram Test Suite', function () {
4+
it('duplicates', function () {
5+
var word = new Isogram('duplicates');
6+
7+
expect(word.isIsogram()).toEqual(true);
8+
});
9+
10+
it('eleven', function () {
11+
var word = new Isogram('eleven');
12+
13+
expect(word.isIsogram()).toEqual(false);
14+
});
15+
16+
it('subdermatoglyphic', function () {
17+
var word = new Isogram('subdermatoglyphic');
18+
19+
expect(word.isIsogram()).toEqual(true);
20+
});
21+
22+
it('Alphabet', function () {
23+
var word = new Isogram('Alphabet');
24+
25+
expect(word.isIsogram()).toEqual(false);
26+
});
27+
28+
it('thumbscrew-japingly', function () {
29+
var word = new Isogram('thumbscrew-japingly');
30+
31+
expect(word.isIsogram()).toEqual(true);
32+
});
33+
34+
it('Hjelmqvist-Gryb-Zock-Pfund-Wax', function () {
35+
var word = new Isogram('Hjelmqvist-Gryb-Zock-Pfund-Wax');
36+
37+
expect(word.isIsogram()).toEqual(true);
38+
});
39+
40+
it('Heizölrückstoßabdämpfung', function () {
41+
var word = new Isogram('Heizölrückstoßabdämpfung');
42+
43+
expect(word.isIsogram()).toEqual(true);
44+
});
45+
46+
it('the quick brown fox', function () {
47+
var word = new Isogram('the quick brown fox');
48+
49+
expect(word.isIsogram()).toEqual(false);
50+
});
51+
52+
it('Emily Jung Schwartzkopf', function () {
53+
var word = new Isogram('Emily Jung Schwartzkopf');
54+
55+
expect(word.isIsogram()).toEqual(true);
56+
});
57+
58+
it('éléphant', function () {
59+
var word = new Isogram('éléphant');
60+
61+
expect(word.isIsogram()).toEqual(false);
62+
});
63+
64+
});

0 commit comments

Comments
 (0)
Please sign in to comment.