Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions exercises/pangram/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@ const notAlpha = /[^a-z]+/gi,
let cleaned,
sortedSet;

class Pangram {

constructor(candidate) {
cleaned = (candidate.replace(notAlpha, '')).toLowerCase();
sortedSet = new Set([...cleaned].sort());
}

isPangram() {
return sortedSet.size === alphaLength;
}
export const isPangram = candidate => {
cleaned = (candidate.replace(notAlpha, '')).toLowerCase();
sortedSet = new Set([...cleaned].sort());
return sortedSet.size === alphaLength;
}

export default Pangram;
32 changes: 11 additions & 21 deletions exercises/pangram/pangram.spec.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,44 @@
import Pangram from './pangram';
import { isPangram } from './pangram';

describe('Pangram()', () => {
test('empty sentence', () => {
const pangram = new Pangram('');
expect(pangram.isPangram()).toBe(false);
expect(isPangram('')).toBe(false);
});

xtest('recognizes a perfect lower case pangram', () => {
const pangram = new Pangram('abcdefghijklmnopqrstuvwxyz');
expect(pangram.isPangram()).toBe(true);
expect(isPangram('abcdefghijklmnopqrstuvwxyz')).toBe(true);
});

xtest('pangram with only lower case', () => {
const pangram = new Pangram('the quick brown fox jumps over the lazy dog');
expect(pangram.isPangram()).toBe(true);
expect(isPangram('the quick brown fox jumps over the lazy dog')).toBe(true);
});

xtest("missing character 'x'", () => {
const pangram = new Pangram('a quick movement of the enemy will jeopardize five gunboats');
expect(pangram.isPangram()).toBe(false);
expect(isPangram('a quick movement of the enemy will jeopardize five gunboats')).toBe(false);
});

xtest("another missing character, e.g. 'h'", () => {
const pangram = new Pangram('five boxing wizards jump quickly at it');
expect(pangram.isPangram()).toBe(false);
expect(isPangram('five boxing wizards jump quickly at it')).toBe(false);
});

xtest('pangram with underscores', () => {
const pangram = new Pangram('the_quick_brown_fox_jumps_over_the_lazy_dog');
expect(pangram.isPangram()).toBe(true);
expect(isPangram('the_quick_brown_fox_jumps_over_the_lazy_dog')).toBe(true);
});

xtest('pangram with numbers', () => {
const pangram = new Pangram('the 1 quick brown fox jumps over the 2 lazy dogs');
expect(pangram.isPangram()).toBe(true);
expect(isPangram('the 1 quick brown fox jumps over the 2 lazy dogs')).toBe(true);
});

xtest('missing letters replaced by numbers', () => {
const pangram = new Pangram('7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog');
expect(pangram.isPangram()).toBe(false);
expect(isPangram('7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog')).toBe(false);
});

xtest('pangram with mixed case and punctuation', () => {
const pangram = new Pangram('"Five quacking Zephyrs jolt my wax bed."');
expect(pangram.isPangram()).toBe(true);
expect(isPangram('"Five quacking Zephyrs jolt my wax bed."')).toBe(true);
});

xtest('upper and lower case versions of the same character should not be counted separately', () => {
const pangram = new Pangram('the quick brown fox jumps over with lazy FX');
expect(pangram.isPangram()).toBe(false);
expect(isPangram('the quick brown fox jumps over with lazy FX')).toBe(false);
});

});