Skip to content

Commit

Permalink
Convert multiple exercises to named exports (#599)
Browse files Browse the repository at this point in the history
Instead of default exports

Issue: #436
Remainder: #600
  • Loading branch information
tejasbubane authored and SleeplessByte committed Jan 24, 2019
1 parent dc4b71a commit 6fe1a0a
Show file tree
Hide file tree
Showing 102 changed files with 118 additions and 176 deletions.
6 changes: 2 additions & 4 deletions docs/SNIPPET.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class HelloWorld {
export class HelloWorld {
hello() {
return 'Hello, World!';
}
}

export default HelloWorld;
};
8 changes: 4 additions & 4 deletions docs/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ $ npm run watch

The skip method instructs the test suite to not run a test, this function could be used also under the aliases: `it.skip(name, fn) or xit(name, fn) or xtest(name, fn)`

- Why they are skipped ?
- Why they are skipped ?
So as to enable users to concentrate on one test at a time and enable one by one as they evolve the solution.

- How to enable them ?
- How to enable them ?
Change xtest to test.

```javascript
Expand All @@ -43,11 +43,11 @@ test('title cased phrases', () => {
## Making Your First JavaScript 2015 Module

Usually, tests on this track will load your implementation by importing it as a
JavaScript module: `import Bob from './bob.js';`. You just
JavaScript module: `import { Bob } from './bob.js';`. You just
need to export your implementation from the referenced file, `bob.js`:

```javascript
export default class Bob {
export class Bob {
hey(message) {
//
// Your solution to the exercise goes here
Expand Down
2 changes: 1 addition & 1 deletion exercises/allergies/allergies.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Allergies from './allergies';
import { Allergies } from './allergies';

describe('Allergies', () => {
test('no allergies at all', () => {
Expand Down
4 changes: 1 addition & 3 deletions exercises/allergies/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const possibleAllergies = [
'cats',
];

class Allergies {
export class Allergies {
constructor(allergenIndex) {
this.allergenIndex = allergenIndex;
}
Expand All @@ -23,5 +23,3 @@ class Allergies {
return this.list().some(allergy => allergy === food);
}
}

export default Allergies;
2 changes: 1 addition & 1 deletion exercises/anagram/anagram.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Anagram from './anagram';
import { Anagram } from './anagram';

describe('Anagram', () => {
test('no matches', () => {
Expand Down
2 changes: 1 addition & 1 deletion exercises/anagram/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const normalize = str => str.toLowerCase().split('').sort().join();
const sameWord = (word, candidate) => word.toLowerCase() === candidate.toLowerCase();
const isAnagram = (word, candiate) => normalize(word) === normalize(candiate);

export default class Anagram {
export class Anagram {
constructor(word) {
this.word = word;
}
Expand Down
16 changes: 8 additions & 8 deletions exercises/beer-song/beer-song.spec.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import Beer from './beer-song';
import { BeerSong } from './beer-song';

describe('Beer', () => {
describe('BeerSong', () => {
test('prints an arbitrary verse', () => {
const expected = `8 bottles of beer on the wall, 8 bottles of beer.
Take one down and pass it around, 7 bottles of beer on the wall.
`;

expect(Beer.verse(8)).toEqual(expected);
expect(BeerSong.verse(8)).toEqual(expected);
});

xtest('handles 1 bottle', () => {
const expected = `1 bottle of beer on the wall, 1 bottle of beer.
Take it down and pass it around, no more bottles of beer on the wall.
`;
expect(Beer.verse(1)).toEqual(expected);
expect(BeerSong.verse(1)).toEqual(expected);
});

xtest('handles 0 bottles', () => {
const expected = `No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
`;
expect(Beer.verse(0)).toEqual(expected);
expect(BeerSong.verse(0)).toEqual(expected);
});

xtest('sings several verses', () => {
Expand All @@ -33,7 +33,7 @@ Take one down and pass it around, 6 bottles of beer on the wall.
6 bottles of beer on the wall, 6 bottles of beer.
Take one down and pass it around, 5 bottles of beer on the wall.
`;
expect(Beer.sing(8, 6)).toEqual(expected);
expect(BeerSong.sing(8, 6)).toEqual(expected);
});

xtest('sings the rest of the verses', () => {
Expand All @@ -49,11 +49,11 @@ Take it down and pass it around, no more bottles of beer on the wall.
No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
`;
expect(Beer.sing(3)).toEqual(expected);
expect(BeerSong.sing(3)).toEqual(expected);
});

xtest('sings all the verses', () => {
const song = Beer.sing();
const song = BeerSong.sing();
expect(song).toEqual(`99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.
Expand Down
4 changes: 1 addition & 3 deletions exercises/beer-song/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function nextBottle(currentVerse) {
return `${bottles(nextVerse(currentVerse)).toLowerCase()} of beer on the wall.\n`;
}

class BeerSong {
export class BeerSong {
static verse(number) {
const line1 = `${bottles(number)} of beer on the wall, `;
const line2 = `${bottles(number).toLowerCase()} of beer.\n`;
Expand All @@ -46,5 +46,3 @@ class BeerSong {
return verses.join('\n');
}
}

export default BeerSong;
2 changes: 1 addition & 1 deletion exercises/binary-search-tree/binary-search-tree.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BinarySearchTree from './binary-search-tree';
import { BinarySearchTree } from './binary-search-tree';

function recordAllData(bst) {
const out = [];
Expand Down
4 changes: 1 addition & 3 deletions exercises/binary-search-tree/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class BinarySearchTree {
export class BinarySearchTree {
constructor(data) {
this.data = data;
this.left = undefined;
Expand Down Expand Up @@ -45,5 +45,3 @@ class BinarySearchTree {
}
}
}

export default BinarySearchTree;
2 changes: 1 addition & 1 deletion exercises/binary-search/binary-search.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BinarySearch from './binary-search';
import { BinarySearch } from './binary-search';

describe('BinarySearch', () => {
const sortedArray = [1, 2, 3, 4, 5, 6];
Expand Down
4 changes: 1 addition & 3 deletions exercises/binary-search/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function recursiveSearch(array, value, start, end) {
return mid;
}

class BinarySearch {
export class BinarySearch {
constructor(array) {
if (isSortedArray(array)) {
this.array = array;
Expand All @@ -36,5 +36,3 @@ class BinarySearch {
return recursiveSearch(this.array, value, 0, this.array.length);
}
}

export default BinarySearch;
2 changes: 1 addition & 1 deletion exercises/binary/binary.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Binary from './binary';
import { Binary } from './binary';

describe('binary', () => {
test('0 is decimal 0', () => expect(new Binary('0').toDecimal()).toEqual(0));
Expand Down
4 changes: 1 addition & 3 deletions exercises/binary/example.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// classy solution, eh?

class Binary {
export class Binary {
constructor(binary) {
this.binary = binary.match(/^[01]*$/) ? parseInt(binary, 2) : 0;
}
Expand All @@ -10,5 +10,3 @@ class Binary {
return Number.isNaN(out) ? 0 : out;
}
}

export default Binary;
2 changes: 1 addition & 1 deletion exercises/bowling/bowling.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Bowling from './bowling';
import { Bowling } from './bowling';

describe('Bowling', () => {
describe('Check game can be scored correctly.', () => {
Expand Down
2 changes: 1 addition & 1 deletion exercises/bowling/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class Bowling {
export class Bowling {
constructor() {
this.maxPins = 10;
this.maxFrames = 10;
Expand Down
2 changes: 1 addition & 1 deletion exercises/change/change.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Change from './change';
import { Change } from './change';

describe('Change', () => {
test('test change for 1 cent', () => {
Expand Down
2 changes: 1 addition & 1 deletion exercises/change/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Candidate {
}
}

export default class Change {
export class Change {
constructor() {
this.candidates = [];
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/clock/clock.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import at from './clock';
import { at } from './clock';

describe('Clock', () => {
describe('Creating a new clock with an initial time', () => {
Expand Down
4 changes: 2 additions & 2 deletions exercises/clock/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function (hour, minute) {
export const at = (hour, minute) => {
const MINUTESPERDAY = 1440;
const HOURSPERDAY = 24;

Expand Down Expand Up @@ -38,4 +38,4 @@ export default function (hour, minute) {
&& clock.minute === otherClock.clock.minute
),
};
}
};
2 changes: 1 addition & 1 deletion exercises/complex-numbers/complex-numbers.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComplexNumber from './complex-numbers.js';
import { ComplexNumber } from './complex-numbers.js';

describe('Complex numbers', () => {
test('Real part of a purely real number', () => {
Expand Down
2 changes: 1 addition & 1 deletion exercises/complex-numbers/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class ComplexNumber {
export class ComplexNumber {
constructor(real, imag) {
this.real = real;
this.imag = imag;
Expand Down
2 changes: 1 addition & 1 deletion exercises/connect/connect.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Board from './connect';
import { Board } from './connect';

describe('Judging a game of connect', () => {
test('an empty board has no winner', () => {
Expand Down
2 changes: 1 addition & 1 deletion exercises/connect/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* "Player O" plays from top to bottom, "Player X" plays from left to right.
* @param board
*/
export default class {
export class Board {
constructor(board) {
this.board = board.map(b => [...b]);
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/crypto-square/crypto-square.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Crypto from './crypto-square';
import { Crypto } from './crypto-square';

describe('Crypto', () => {
test('normalize strange characters', () => {
Expand Down
2 changes: 1 addition & 1 deletion exercises/crypto-square/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class Square {
export class Crypto {
constructor(input) {
this.input = input;
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/custom-set/custom-set.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CustomSet from './custom-set';
import { CustomSet } from './custom-set';

describe('CustomSet', () => {
describe('empty: returns true if the set contains no elements', () => {
Expand Down
2 changes: 1 addition & 1 deletion exercises/custom-set/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class CustomSet {
export class CustomSet {
constructor(data = []) {
this.data = {};
data.forEach(el => this.add(el));
Expand Down
2 changes: 1 addition & 1 deletion exercises/diamond/diamond.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Diamond from './diamond.js';
import { Diamond } from './diamond.js';

describe('Make diamond function', () => {
const diamond = new Diamond();
Expand Down
2 changes: 1 addition & 1 deletion exercises/diamond/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class Diamond {
export class Diamond {
makeDiamond(input) {
const inputIndex = input.charCodeAt() - 65;
let output = '';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Squares from './difference-of-squares';
import { Squares } from './difference-of-squares';

describe('difference-of-squares', () => {
const squares1 = new Squares(1);
Expand Down
2 changes: 1 addition & 1 deletion exercises/difference-of-squares/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class Squares {
export class Squares {
constructor(max) {
this.max = max;
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/diffie-hellman/diffie-hellman.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-new */
import DiffieHellman from './diffie-hellman';
import { DiffieHellman } from './diffie-hellman';

describe('diffie-hellman', () => {
const p = 23;
Expand Down
2 changes: 1 addition & 1 deletion exercises/diffie-hellman/example.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion exercises/etl/etl.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import transform from './etl';
import { transform } from './etl';

describe('Transform', () => {
test('transforms one value', () => {
Expand Down
6 changes: 2 additions & 4 deletions exercises/etl/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function transform(input) {
export const transform = (input) => {
const output = {};

Object.keys(input).forEach((key) => {
Expand All @@ -11,6 +11,4 @@ function transform(input) {
});

return output;
}

export default transform;
};
2 changes: 1 addition & 1 deletion exercises/flatten-array/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class Flattener {
export class Flattener {
flatten(arr) {
return arr
.reduce((acc, el) => (Array.isArray(el)
Expand Down
2 changes: 1 addition & 1 deletion exercises/flatten-array/flatten-array.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Flattener from './flatten-array.js';
import { Flattener } from './flatten-array.js';

describe('FlattenArray', () => {
const flattener = new Flattener();
Expand Down
2 changes: 1 addition & 1 deletion exercises/food-chain/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class Song {
export class Song {
/**
* @param {Number} number
* verse number
Expand Down
2 changes: 1 addition & 1 deletion exercises/food-chain/food-chain.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Song from './food-chain';
import { Song } from './food-chain';

describe('Food Chain', () => {
let song;
Expand Down
4 changes: 1 addition & 3 deletions exercises/forth/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Forth {
export class Forth {
constructor(){
this.stack = [];
this.commands = Forth.basicCommands();
Expand Down Expand Up @@ -59,5 +59,3 @@ class Forth {
};
}
}

export default Forth;
2 changes: 1 addition & 1 deletion exercises/forth/forth.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Forth from './forth';
import { Forth } from './forth';

describe('Forth', () => {
let forth;
Expand Down
Loading

0 comments on commit 6fe1a0a

Please sign in to comment.