Avatar of PatrickMcSweeny

PatrickMcSweeny's solution

to Acronym in the JavaScript Track

Published at Aug 21 2019 · 0 comments
Instructions
Test suite
Solution

Convert a phrase to its acronym.

Techies love their TLA (Three Letter Acronyms)!

Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).

Setup

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

https://exercism.io/tracks/javascript/installation

Requirements

Install assignment dependencies:

$ npm install

Making the test suite pass

Execute the tests with:

$ npm test

In the test suites all tests but the first have been skipped.

Once you get a test passing, you can enable the next one by changing xtest to test.

Source

Julien Vanier https://github.com/monkbroc

Submitting Incomplete Solutions

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

acronym.spec.js

import { parse } from './acronym';

describe('Acronyms are produced from', () => {
  test('title cased phrases', () => {
    expect(parse('Portable Network Graphics')).toEqual('PNG');
  });

  xtest('other title cased phrases', () => {
    expect(parse('Ruby on Rails')).toEqual('ROR');
  });

  xtest('phrases with punctuation', () => {
    expect(parse('First In, First Out')).toEqual('FIFO');
  });

  xtest('phrases with all uppercase words', () => {
    expect(parse('GNU Image Manipulation Program')).toEqual('GIMP');
  });

  xtest('phrases with punctuation without whitespace', () => {
    expect(parse('Complementary metal-oxide semiconductor')).toEqual('CMOS');
  });

  xtest('long phrases', () => {
    expect(parse('Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me'))
      .toEqual('ROTFLSHTMDCOALM');
  });

  xtest('phrases with consecutive delimiters', () => {
    expect(parse('Something - I made up from thin air')).toEqual('SIMUFTA');
  });

  xtest('phrases with apostrophes', () => {
    expect(parse("Halley's Comet")).toEqual('HC');
  });

  xtest('phrases with underscore emphasis', () => {
    expect(parse('The Road _Not_ Taken')).toEqual('TRNT');
  });
});
const firstLetters = phrase =>
  phrase
    .replace(/_|\'/g, "")
    .match(/\b\w/g);

export const parse = phrase =>
  firstLetters(phrase)
    .join("")
    .toUpperCase();

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned 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 you could read more about to improve your understanding?