Skip to content

Commit 24f75ff

Browse files
author
programmiri
committed
Add excercise Pangram and solution for it
1 parent 8c30416 commit 24f75ff

File tree

7 files changed

+4427
-0
lines changed

7 files changed

+4427
-0
lines changed

pangram/.eslintrc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"root": true,
3+
"parser": "babel-eslint",
4+
"parserOptions": {
5+
"ecmaVersion": 7,
6+
"sourceType": "module"
7+
},
8+
"env": {
9+
"es6": true,
10+
"node": true,
11+
"jest": true
12+
},
13+
"extends": [
14+
"eslint:recommended",
15+
"plugin:import/errors",
16+
"plugin:import/warnings"
17+
],
18+
"rules": {
19+
"linebreak-style": "off",
20+
21+
"import/extensions": "off",
22+
"import/no-default-export": "off",
23+
"import/no-unresolved": "off",
24+
"import/prefer-default-export": "off"
25+
}
26+
}

pangram/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Pangram
2+
3+
Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma,
4+
"every letter") is a sentence using every letter of the alphabet at least once.
5+
The best known English pangram is:
6+
> The quick brown fox jumps over the lazy dog.
7+
8+
The alphabet used consists of ASCII letters `a` to `z`, inclusive, and is case
9+
insensitive. Input will not contain non-ASCII symbols.
10+
11+
## Setup
12+
13+
Go through the setup instructions for Javascript to install the necessary
14+
dependencies:
15+
16+
[https://exercism.io/tracks/javascript/installation](https://exercism.io/tracks/javascript/installation)
17+
18+
## Requirements
19+
20+
Install assignment dependencies:
21+
22+
```bash
23+
$ npm install
24+
```
25+
26+
## Making the test suite pass
27+
28+
Execute the tests with:
29+
30+
```bash
31+
$ npm test
32+
```
33+
34+
In the test suites all tests but the first have been skipped.
35+
36+
Once you get a test passing, you can enable the next one by changing `xtest` to
37+
`test`.
38+
39+
## Source
40+
41+
Wikipedia [https://en.wikipedia.org/wiki/Pangram](https://en.wikipedia.org/wiki/Pangram)
42+
43+
## Submitting Incomplete Solutions
44+
45+
It's possible to submit an incomplete solution so you can see how others have
46+
completed the exercise.

pangram/babel.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/env',
5+
{
6+
targets: {
7+
node: 'current',
8+
},
9+
useBuiltIns: false,
10+
},
11+
12+
],
13+
],
14+
};

pangram/package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "exercism-javascript",
3+
"description": "Exercism exercises in Javascript.",
4+
"author": "Katrina Owen",
5+
"private": true,
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/exercism/javascript"
9+
},
10+
"devDependencies": {
11+
"@babel/cli": "^7.5.5",
12+
"@babel/core": "^7.5.5",
13+
"@babel/preset-env": "^7.5.5",
14+
"@types/jest": "^24.0.16",
15+
"@types/node": "^12.6.8",
16+
"babel-eslint": "^10.0.2",
17+
"babel-jest": "^24.8.0",
18+
"eslint": "^6.1.0",
19+
"eslint-plugin-import": "^2.18.2",
20+
"jest": "^24.8.0"
21+
},
22+
"jest": {
23+
"modulePathIgnorePatterns": [
24+
"package.json"
25+
]
26+
},
27+
"scripts": {
28+
"test": "jest --no-cache ./*",
29+
"watch": "jest --no-cache --watch ./*",
30+
"lint": "eslint .",
31+
"lint-test": "eslint . && jest --no-cache ./* "
32+
},
33+
"license": "MIT",
34+
"dependencies": {}
35+
}

pangram/pangram.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// This is only a SKELETON file for the 'Pangram' exercise. It's been provided as a
3+
// convenience to get you started writing code faster.
4+
//
5+
6+
const alphabet = [
7+
'a',
8+
'b',
9+
'c',
10+
'd',
11+
'e',
12+
'f',
13+
'c',
14+
'h',
15+
'i',
16+
'j',
17+
'k',
18+
'l',
19+
'm',
20+
'n',
21+
'o',
22+
'p',
23+
'q',
24+
'r',
25+
's',
26+
't',
27+
'u',
28+
'v',
29+
'w',
30+
'x',
31+
'y',
32+
'z',
33+
];
34+
export const isPangram = (string) => {
35+
return alphabet.every((char) => string.toLowerCase().includes(char));
36+
};

pangram/pangram.spec.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { isPangram } from './pangram';
2+
3+
describe('Pangram()', () => {
4+
test('empty sentence', () => {
5+
expect(isPangram('')).toBe(false);
6+
});
7+
8+
test('recognizes a perfect lower case pangram', () => {
9+
expect(isPangram('abcdefghijklmnopqrstuvwxyz')).toBe(true);
10+
});
11+
12+
test('pangram with only lower case', () => {
13+
expect(isPangram('the quick brown fox jumps over the lazy dog')).toBe(true);
14+
});
15+
16+
test("missing character 'x'", () => {
17+
expect(
18+
isPangram('a quick movement of the enemy will jeopardize five gunboats')
19+
).toBe(false);
20+
});
21+
22+
test("another missing character, e.g. 'h'", () => {
23+
expect(isPangram('five boxing wizards jump quickly at it')).toBe(false);
24+
});
25+
26+
test('pangram with underscores', () => {
27+
expect(isPangram('the_quick_brown_fox_jumps_over_the_lazy_dog')).toBe(true);
28+
});
29+
30+
test('pangram with numbers', () => {
31+
expect(isPangram('the 1 quick brown fox jumps over the 2 lazy dogs')).toBe(
32+
true
33+
);
34+
});
35+
36+
test('missing letters replaced by numbers', () => {
37+
expect(isPangram('7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog')).toBe(
38+
false
39+
);
40+
});
41+
42+
test('pangram with mixed case and punctuation', () => {
43+
expect(isPangram('"Five quacking Zephyrs jolt my wax bed."')).toBe(true);
44+
});
45+
46+
test('upper and lower case versions of the same character should not be counted separately', () => {
47+
expect(isPangram('the quick brown fox jumps over with lazy FX')).toBe(
48+
false
49+
);
50+
});
51+
});

0 commit comments

Comments
 (0)