Skip to content

Commit 658a964

Browse files
authored
Add ETL (#332)
1 parent 38960f4 commit 658a964

File tree

8 files changed

+136
-0
lines changed

8 files changed

+136
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@
168168
"prerequisites": [],
169169
"difficulty": 2
170170
},
171+
{
172+
"slug": "etl",
173+
"name": "ETL",
174+
"uuid": "2a1c165e-3ee8-47a4-b19d-7e44c79458f0",
175+
"practices": [],
176+
"prerequisites": [],
177+
"difficulty": 2
178+
},
171179
{
172180
"slug": "gigasecond",
173181
"name": "Gigasecond",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Instructions
2+
3+
Your task is to change the data format of letters and their point values in the game.
4+
5+
Currently, letters are stored in groups based on their score, in a one-to-many mapping.
6+
7+
- 1 point: "A", "E", "I", "O", "U", "L", "N", "R", "S", "T",
8+
- 2 points: "D", "G",
9+
- 3 points: "B", "C", "M", "P",
10+
- 4 points: "F", "H", "V", "W", "Y",
11+
- 5 points: "K",
12+
- 8 points: "J", "X",
13+
- 10 points: "Q", "Z",
14+
15+
This needs to be changed to store each individual letter with its score in a one-to-one mapping.
16+
17+
- "a" is worth 1 point.
18+
- "b" is worth 3 points.
19+
- "c" is worth 3 points.
20+
- "d" is worth 2 points.
21+
- etc.
22+
23+
As part of this change, the team has also decided to change the letters to be lower-case rather than upper-case.
24+
25+
~~~~exercism/note
26+
If you want to look at how the data was previously structured and how it needs to change, take a look at the examples in the test suite.
27+
~~~~
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Introduction
2+
3+
You work for a company that makes an online multiplayer game called Lexiconia.
4+
5+
To play the game, each player is given 13 letters, which they must rearrange to create words.
6+
Different letters have different point values, since it's easier to create words with some letters than others.
7+
8+
The game was originally launched in English, but it is very popular, and now the company wants to expand to other languages as well.
9+
10+
Different languages need to support different point values for letters.
11+
The point values are determined by how often letters are used, compared to other letters in that language.
12+
13+
For example, the letter 'C' is quite common in English, and is only worth 3 points.
14+
But in Norwegian it's a very rare letter, and is worth 10 points.
15+
16+
To make it easier to add new languages, your team needs to change the way letters and their point values are stored in the game.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"BNAndras"
4+
],
5+
"files": {
6+
"solution": [
7+
"etl.coffee"
8+
],
9+
"test": [
10+
"etl.spec.coffee"
11+
],
12+
"example": [
13+
".meta/example.coffee"
14+
]
15+
},
16+
"blurb": "Change the data format for scoring a game to more easily add other languages.",
17+
"source": "Based on an exercise by the JumpstartLab team for students at The Turing School of Software and Design.",
18+
"source_url": "https://turing.edu"
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Etl
2+
@transform: (legacy) ->
3+
results = {}
4+
for score, letters of legacy
5+
for letter in letters
6+
results[letter.toLowerCase()] = +score
7+
results
8+
9+
module.exports = Etl
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[78a7a9f9-4490-4a47-8ee9-5a38bb47d28f]
13+
description = "single letter"
14+
15+
[60dbd000-451d-44c7-bdbb-97c73ac1f497]
16+
description = "single score with multiple letters"
17+
18+
[f5c5de0c-301f-4fdd-a0e5-df97d4214f54]
19+
description = "multiple scores with multiple letters"
20+
21+
[5db8ea89-ecb4-4dcd-902f-2b418cc87b9d]
22+
description = "multiple scores with differing numbers of letters"

exercises/practice/etl/etl.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Etl
2+
@transform: (legacy) ->
3+
4+
module.exports = Etl
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Etl = require './etl'
2+
3+
describe "ETL", ->
4+
it 'single letter', ->
5+
result = Etl.transform { 1: ['A'] }
6+
expect(result).toEqual { 'a': 1 }
7+
8+
xit 'single score with multiple letters', ->
9+
result = Etl.transform { 1: ['A', 'E', 'I', 'O', 'U'] }
10+
expect(result).toEqual { 'a': 1, 'e': 1, 'i': 1, 'o': 1, 'u': 1 }
11+
12+
xit 'multiple scores with multiple letters', ->
13+
result = Etl.transform { 1: ['A', 'E'], 2: ['D', 'G'] }
14+
expect(result).toEqual { 'a': 1, 'd': 2, 'e': 1, 'g': 2 }
15+
16+
xit 'multiple scores with differing numbers of letters', ->
17+
result = Etl.transform {
18+
1: ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T']
19+
2: ['D', 'G']
20+
3: ['B', 'C', 'M', 'P']
21+
4: ['F', 'H', 'V', 'W', 'Y']
22+
5: ['K']
23+
8: ['J', 'X']
24+
10: ['Q', 'Z']
25+
}
26+
expect(result).toEqual {
27+
'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f': 4, 'g': 2, 'h': 4,
28+
'i': 1, 'j': 8, 'k': 5, 'l': 1, 'm': 3, 'n': 1, 'o': 1, 'p': 3,
29+
'q': 10, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 4, 'w': 4, 'x': 8,
30+
'y': 4, 'z': 10
31+
}

0 commit comments

Comments
 (0)