Skip to content

Commit bd8155d

Browse files
committed
Convert challenge shape and everything to ES modules
1 parent 0b465fe commit bd8155d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+660
-358
lines changed

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
preset: 'ts-jest',
33
testEnvironment: 'node',
44
};

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"name": "mancjs-golf",
33
"version": "0.0.1",
44
"description": "A code golf game server for JavaScript",
5+
"type": "module",
56
"scripts": {
6-
"start": "CG_ADMIN_PASSWORD=admin ts-node src",
7+
"start": "CG_ADMIN_PASSWORD=admin ts-node --esm --files --project tsconfig.json src/index.ts",
78
"tests": "jest --runInBand",
89
"tests-watch": "jest --watch",
910
"format": "prettier --write '**/*'",

src/@types/jsmin.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module 'jsmin' {
2+
export const jsmin: (code: string, something: number) => string;
3+
}

src/@types/mustachex.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module 'mustachex' {
2+
export const express: (
3+
path: string,
4+
options: object,
5+
callback: (e: any, rendered?: string) => void
6+
) => void;
7+
}
+13-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import type { Challenge } from '../types';
2-
import solution from './solution';
1+
import type { Challenge } from '../types.js';
32

4-
const challenge: Challenge = {
5-
input: '',
3+
const challenge: Challenge<[], string> = {
64
title: 'Hello World',
7-
output: solution(),
85
description: `Write a function that returns "Hello, World!".`,
9-
example: `⟶ "Hello, World!"`,
6+
example: {
7+
input: [],
8+
output: 'Hello, World!',
9+
},
10+
assertions: [
11+
{
12+
input: [],
13+
output: 'Hello, World!',
14+
},
15+
],
1016
};
1117

12-
export = challenge;
18+
export default challenge;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
declare function play(): string;
22

3-
export = play;
3+
export default play;
+13-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import type { Challenge } from '../types';
2-
import solution from './solution';
1+
import type { Challenge } from '../types.js';
32

4-
const input = 877209536;
5-
6-
const challenge: Challenge = {
7-
input,
3+
const challenge: Challenge<[input: number], string> = {
84
title: 'Number Reader',
9-
output: solution(input),
105
description: `Write a function that takes a number and converts it to the equivalant string.`,
11-
example: `12341 ⟶ "one two three four one"`,
6+
example: {
7+
input: [12341],
8+
output: 'one two three four one',
9+
},
10+
assertions: [
11+
{
12+
input: [877209536],
13+
output: 'eight seven seven two zero nine five three six',
14+
},
15+
],
1216
};
1317

14-
export = challenge;
18+
export default challenge;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
declare function play(n: number): string;
22

3-
export = play;
3+
export default play;
+54-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,59 @@
1-
import type { Challenge } from '../types';
2-
import solution from './solution';
1+
import type { Challenge } from '../types.js';
32

4-
const input = [
5-
[1, 2, 3, 4, 5],
6-
['unu', 'du', 'tri', 'kvar', 'kvin'],
7-
['v', 'w', 'x', 'y', 'z'],
8-
];
9-
10-
const challenge: Challenge = {
11-
input,
3+
const challenge: Challenge<
4+
[input: readonly (readonly (string | number)[])[]],
5+
readonly (string | number)[]
6+
> = {
127
title: 'Array Flatten',
13-
output: solution(input),
148
description: `Write a function that takes an array of three other arrays and returns a single, flattened array. The second array's values should remain in the middle, but the first and third should be swapped.`,
15-
example: `[[4, 5, 6], ["a", "b", "c"], [1, 2, 3]] ⟶ [1, 2, 3, "a", "b", "c", 4, 5, 6]`,
9+
example: {
10+
input: [
11+
[
12+
[4, 5, 6],
13+
['a', 'b', 'c'],
14+
[1, 2, 3],
15+
],
16+
],
17+
output: [1, 2, 3, 'a', 'b', 'c', 4, 5, 6],
18+
},
19+
assertions: [
20+
{
21+
input: [
22+
[
23+
[4, 5, 6],
24+
['a', 'b', 'c'],
25+
[1, 2, 3],
26+
],
27+
],
28+
output: [1, 2, 3, 'a', 'b', 'c', 4, 5, 6],
29+
},
30+
{
31+
input: [
32+
[
33+
[1, 2, 3, 4, 5],
34+
['unu', 'du', 'tri', 'kvar', 'kvin'],
35+
['v', 'w', 'x', 'y', 'z'],
36+
],
37+
],
38+
output: [
39+
'v',
40+
'w',
41+
'x',
42+
'y',
43+
'z',
44+
'unu',
45+
'du',
46+
'tri',
47+
'kvar',
48+
'kvin',
49+
1,
50+
2,
51+
3,
52+
4,
53+
5,
54+
],
55+
},
56+
],
1657
};
1758

18-
export = challenge;
59+
export default challenge;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
declare function play(n: any[][]): any[];
22

3-
export = play;
3+
export default play;
+27-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
import type { Challenge } from '../types';
2-
import solution from './solution';
1+
import type { Challenge } from '../types.js';
32

4-
const input =
5-
"A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution. Digital signatures provide part of the solution, but the main benefits are lost if a trusted third party is still required to prevent double-spending. We propose a solution to the double-spending problem using a peer-to-peer network. The network timestamps transactions by hashing them into an ongoing chain of hash-based proof-of-work, forming a record that cannot be changed without redoing the proof-of-work. The longest chain not only serves as proof of the sequence of events witnessed, but proof that it came from the largest pool of CPU power. As long as a majority of CPU power is controlled by nodes that are not cooperating to attack the network, they'll generate the longest chain and outpace attackers. The network itself requires minimal structure. Messages are broadcast on a best effort basis, and nodes can leave and rejoin the network at will, accepting the longest proof-of-work chain as proof of what happened while they were gone .";
6-
7-
const challenge: Challenge = {
8-
input,
3+
const challenge: Challenge<[input: string], number> = {
94
title: 'Word Count',
10-
output: solution(input),
115
description: `Write a function that takes a string of text and returns the word count. A valid word is anything not made up of only of spaces or punctuation.`,
12-
example: `"You know what would make a great coffee table book? A coffee table book about coffee tables! Get it?" ⟶ 19, "Hello world ." ⟶ 2`,
6+
example: {
7+
input: [
8+
'You know what would make a great coffee table book? A coffee table book about coffee tables! Get it?',
9+
],
10+
output: 19,
11+
},
12+
assertions: [
13+
{
14+
input: ['Hello world .'],
15+
output: 2,
16+
},
17+
{
18+
input: [
19+
'You know what would make a great coffee table book? A coffee table book about coffee tables! Get it?',
20+
],
21+
output: 19,
22+
},
23+
{
24+
input: [
25+
"A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution. Digital signatures provide part of the solution, but the main benefits are lost if a trusted third party is still required to prevent double-spending. We propose a solution to the double-spending problem using a peer-to-peer network. The network timestamps transactions by hashing them into an ongoing chain of hash-based proof-of-work, forming a record that cannot be changed without redoing the proof-of-work. The longest chain not only serves as proof of the sequence of events witnessed, but proof that it came from the largest pool of CPU power. As long as a majority of CPU power is controlled by nodes that are not cooperating to attack the network, they'll generate the longest chain and outpace attackers. The network itself requires minimal structure. Messages are broadcast on a best effort basis, and nodes can leave and rejoin the network at will, accepting the longest proof-of-work chain as proof of what happened while they were gone .",
26+
],
27+
output: 179,
28+
},
29+
],
1330
};
1431

15-
export = challenge;
32+
export default challenge;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
declare function play(str: string): number;
22

3-
export = play;
3+
export default play;

src/challenges/c12-remainder/index.ts

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1-
import type { Challenge } from '../types';
2-
import solution from './solution';
1+
import type { Challenge } from '../types.js';
32

4-
const input = [7362, 392];
5-
6-
const challenge: Challenge = {
7-
input,
3+
const challenge: Challenge<[input: [number, number]], number> = {
84
title: 'Remainder',
9-
output: solution(input),
105
description: `Write a function that takes an array of two numbers – the first the dividend, the second the divisor – and returns the remainder.`,
11-
example: `[10, 2] ⟶ 0, [25, 4] ⟶ 1, [12, 7] ⟶ 5`,
6+
example: {
7+
input: [[10, 2]],
8+
output: 0,
9+
},
10+
assertions: [
11+
{
12+
input: [[10, 2]],
13+
output: 0,
14+
},
15+
{
16+
input: [[25, 4]],
17+
output: 1,
18+
},
19+
{
20+
input: [[12, 7]],
21+
output: 5,
22+
},
23+
{
24+
input: [[7362, 392]],
25+
output: 306,
26+
},
27+
],
1228
};
1329

14-
export = challenge;
30+
export default challenge;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
declare function play(n: number[]): number;
22

3-
export = play;
3+
export default play;
+21-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
import { Challenge } from '../types';
2-
import solution from './solution';
1+
import type { Challenge } from '../types.js';
32

4-
const input = [10, 1, 150, 34, 300, 250, 12, 22, 23, 65, 33, 16, 1, 2];
3+
class ArrayNoSort extends Array {
4+
public override sort() {
5+
return ['allowed', 'no', 'sort'] as unknown as this;
6+
}
7+
}
58

6-
const challenge: Challenge = {
7-
input,
9+
const challenge: Challenge<[arr: readonly number[]], readonly number[]> = {
810
title: 'Sort The Numbers',
9-
output: solution(input),
1011
description:
1112
'Write a function that takes an array of numbers and returns a sorted array in ascending order.',
12-
example: `[3, 5, 2, 4, 1] ⟶ [1, 2, 3, 4, 5]`,
13-
rules: ['no-sort'],
13+
example: {
14+
input: [[3, 5, 2, 4, 1]],
15+
output: [1, 2, 3, 4, 5],
16+
},
17+
assertions: [
18+
{
19+
input: [[10, 1, 150, 34, 300, 250, 12, 22, 23, 65, 33, 16, 1, 2]],
20+
output: [1, 1, 2, 10, 12, 16, 22, 23, 33, 34, 65, 150, 250, 300],
21+
},
22+
],
23+
context: {
24+
Array: ArrayNoSort,
25+
},
1426
};
1527

16-
export = challenge;
28+
export default challenge;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
declare function play(n: number[]): number[];
22

3-
export = play;
3+
export default play;
+23-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1-
import { Challenge } from '../types';
2-
import solution from './solution';
1+
import type { Challenge } from '../types.js';
32

4-
const input = 743243892;
5-
6-
const challenge: Challenge = {
7-
input,
3+
const challenge: Challenge<[input: number], string> = {
84
title: 'Number To Words',
9-
output: solution(input),
105
description: `Write a function that takes a number and converts it to words.`,
11-
example: `2 ⟶ "two", 301 ⟶ "three hundred one", 12341 ⟶ "twelve thousand three hundred forty one", 1290489 ⟶ "one million two hundred ninety thousand four hundred eighty nine"`,
6+
example: {
7+
input: [12341],
8+
output: 'twelve thousand three hundred forty one',
9+
},
10+
assertions: [
11+
{
12+
input: [12341],
13+
output: 'twelve thousand three hundred forty one',
14+
},
15+
{
16+
input: [1290489],
17+
output:
18+
'one million two hundred ninety thousand four hundred eighty nine',
19+
},
20+
{
21+
input: [743243892],
22+
output:
23+
'seven hundred forty three million two hundred forty three thousand eight hundred ninety two',
24+
},
25+
],
1226
};
1327

14-
export = challenge;
28+
export default challenge;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
declare function play(num: number): string;
22

3-
export = play;
3+
export default play;
+21-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
import { Challenge } from '../types';
2-
import solution from './solution';
1+
import type { Challenge } from '../types.js';
32

4-
const input = 2476;
5-
6-
const challenge: Challenge = {
7-
input,
3+
const challenge: Challenge<[input: number], string> = {
84
title: 'Roman Numerals',
9-
output: solution(input),
105
description: `Write a function that converts numbers to roman numerals.`,
11-
example: `23 ⟶ "XXIII", 2743 ⟶ "MMDCCXLIII"`,
6+
example: {
7+
input: [23],
8+
output: 'XXIII',
9+
},
10+
assertions: [
11+
{
12+
input: [23],
13+
output: 'XXIII',
14+
},
15+
{
16+
input: [2743],
17+
output: 'MMDCCXLIII',
18+
},
19+
{
20+
input: [2476],
21+
output: 'MMCDLXXVI',
22+
},
23+
],
1224
};
1325

14-
export = challenge;
26+
export default challenge;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
declare function play(num: number): string;
22

3-
export = play;
3+
export default play;

0 commit comments

Comments
 (0)