Avatar of PatrickMcSweeny
0
0
Genius
0
0

PatrickMcSweeny's solution

to Pangram in the JavaScript Track

0
0
Genius
0
0
Instructions
Test suite
Solution

Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is:

The quick brown fox jumps over the lazy dog.

The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Input will not contain non-ASCII symbols.

Setup

Go through the setup instructions for JavaScript to install the necessary dependencies:

http://exercism.io/languages/javascript/installation

Running the test suite

The provided test suite uses Jasmine. You can install it by opening a terminal window and running the following command:

npm install -g jasmine

Run the test suite from the exercise directory with:

jasmine pangram.spec.js

In many test suites all but the first test have been marked "pending". Once you get a test passing, activate the next one by changing xit to it.

Source

Wikipedia https://en.wikipedia.org/wiki/Pangram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

pangram.spec.js

var Pangram = require('./pangram');

describe('Pangram()', function ()  {
  it('sentence empty', function () {
    var pangram = new Pangram('');
    expect(pangram.isPangram()).toBe(false);
  });

  xit('recognizes a perfect lower case pangram', function ()  {
    var pangram = new Pangram('abcdefghijklmnopqrstuvwxyz');
    expect(pangram.isPangram()).toBe(true);
  });

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

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

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

  xit('pangram with underscores', function () {
    var pangram = new Pangram('the_quick_brown_fox_jumps_over_the_lazy_dog');
    expect(pangram.isPangram()).toBe(true);
  });

  xit('pangram with numbers', function () {
    var pangram = new Pangram('the 1 quick brown fox jumps over the 2 lazy dog');
    expect(pangram.isPangram()).toBe(true);
  });

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

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

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

var Pangram = function(input) {
  this.input = input.toLowerCase();
};

Pangram.prototype.isPangram = function(){
  var input = this.input;
  return alphabet.split("").every(function(letter) {
    return input.includes(letter);
  });
};

module.exports = Pangram;

What can you learn from this solution?

A huge amount can be learnt from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that I could read more about to develop my understanding?