Skip to content

Commit 18ce27f

Browse files
authored
Add line-up exercise (#390)
1 parent 0804e09 commit 18ce27f

File tree

8 files changed

+222
-0
lines changed

8 files changed

+222
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@
285285
"prerequisites": [],
286286
"difficulty": 2
287287
},
288+
{
289+
"slug": "line-up",
290+
"name": "Line Up",
291+
"uuid": "e73766c8-49bc-46ae-a814-630f02cb0d60",
292+
"practices": [],
293+
"prerequisites": [],
294+
"difficulty": 2
295+
},
288296
{
289297
"slug": "linked-list",
290298
"name": "Linked List",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Instructions
2+
3+
Given a name and a number, your task is to produce a sentence using that name and that number as an [ordinal numeral][ordinal-numeral].
4+
Yaʻqūb expects to use numbers from 1 up to 999.
5+
6+
Rules:
7+
8+
- Numbers ending in 1 (except for 11) → `"st"`
9+
- Numbers ending in 2 (except for 12) → `"nd"`
10+
- Numbers ending in 3 (except for 13) → `"rd"`
11+
- All other numbers → `"th"`
12+
13+
Examples:
14+
15+
- `"Mary", 1``"Mary, you are the 1st customer we serve today. Thank you!"`
16+
- `"John", 12``"John, you are the 12th customer we serve today. Thank you!"`
17+
- `"Dahir", 162``"Dahir, you are the 162nd customer we serve today. Thank you!"`
18+
19+
[ordinal-numeral]: https://en.wikipedia.org/wiki/Ordinal_numeral
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Introduction
2+
3+
Your friend Yaʻqūb works the counter at a deli in town, slicing, weighing, and wrapping orders for a line of hungry customers that gets longer every day.
4+
Waiting customers are starting to lose track of who is next, so he wants numbered tickets they can use to track the order in which they arrive.
5+
6+
To make the customers feel special, he does not want the ticket to have only a number on it.
7+
They shall get a proper English sentence with their name and number on it.
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+
"line-up.coffee"
8+
],
9+
"test": [
10+
"line-up.spec.coffee"
11+
],
12+
"example": [
13+
".meta/example.coffee"
14+
]
15+
},
16+
"blurb": "Help lining up customers at Yaʻqūb's Deli.",
17+
"source": "mk-mxp, based on previous work from Exercism contributors codedge and neenjaw",
18+
"source_url": "https://forum.exercism.org/t/new-exercise-ordinal-numbers/19147"
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Lineup
2+
@format: (name, number) ->
3+
suffix = @getSuffix number
4+
"#{name}, you are the #{number}#{suffix} customer we serve today. Thank you!"
5+
6+
@getSuffix: (number) ->
7+
mod100 = number % 100
8+
mod10 = number % 10
9+
if mod100 in [11, 12, 13]
10+
'th'
11+
else if mod10 is 1
12+
'st'
13+
else if mod10 is 2
14+
'nd'
15+
else if mod10 is 3
16+
'rd'
17+
else
18+
'th'
19+
20+
module.exports = Lineup
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
[7760d1b8-4864-4db4-953b-0fa7c047dbc0]
13+
description = "format smallest non-exceptional ordinal numeral 4"
14+
15+
[e8b7c715-6baa-4f7b-8fb3-2fa48044ab7a]
16+
description = "format greatest single digit non-exceptional ordinal numeral 9"
17+
18+
[f370aae9-7ae7-4247-90ce-e8ff8c6934df]
19+
description = "format non-exceptional ordinal numeral 5"
20+
21+
[37f10dea-42a2-49de-bb92-0b690b677908]
22+
description = "format non-exceptional ordinal numeral 6"
23+
24+
[d8dfb9a2-3a1f-4fee-9dae-01af3600054e]
25+
description = "format non-exceptional ordinal numeral 7"
26+
27+
[505ec372-1803-42b1-9377-6934890fd055]
28+
description = "format non-exceptional ordinal numeral 8"
29+
30+
[8267072d-be1f-4f70-b34a-76b7557a47b9]
31+
description = "format exceptional ordinal numeral 1"
32+
33+
[4d8753cb-0364-4b29-84b8-4374a4fa2e3f]
34+
description = "format exceptional ordinal numeral 2"
35+
36+
[8d44c223-3a7e-4f48-a0ca-78e67bf98aa7]
37+
description = "format exceptional ordinal numeral 3"
38+
39+
[6c4f6c88-b306-4f40-bc78-97cdd583c21a]
40+
description = "format smallest two digit non-exceptional ordinal numeral 10"
41+
42+
[e257a43f-d2b1-457a-97df-25f0923fc62a]
43+
description = "format non-exceptional ordinal numeral 11"
44+
45+
[bb1db695-4d64-457f-81b8-4f5a2107e3f4]
46+
description = "format non-exceptional ordinal numeral 12"
47+
48+
[60a3187c-9403-4835-97de-4f10ebfd63e2]
49+
description = "format non-exceptional ordinal numeral 13"
50+
51+
[2bdcebc5-c029-4874-b6cc-e9bec80d603a]
52+
description = "format exceptional ordinal numeral 21"
53+
54+
[74ee2317-0295-49d2-baf0-d56bcefa14e3]
55+
description = "format exceptional ordinal numeral 62"
56+
57+
[b37c332d-7f68-40e3-8503-e43cbd67a0c4]
58+
description = "format exceptional ordinal numeral 100"
59+
60+
[0375f250-ce92-4195-9555-00e28ccc4d99]
61+
description = "format exceptional ordinal numeral 101"
62+
63+
[0d8a4974-9a8a-45a4-aca7-a9fb473c9836]
64+
description = "format non-exceptional ordinal numeral 112"
65+
66+
[06b62efe-199e-4ce7-970d-4bf73945713f]
67+
description = "format exceptional ordinal numeral 123"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Lineup
2+
@format: (name, number) ->
3+
4+
module.exports = Lineup
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Lineup = require './line-up'
2+
3+
describe 'Lineup', ->
4+
it 'format smallest non-exceptional ordinal numeral 4', ->
5+
result = Lineup.format 'Gianna', 4
6+
expect(result).toEqual 'Gianna, you are the 4th customer we serve today. Thank you!'
7+
8+
xit 'format greatest single digit non-exceptional ordinal numeral 9', ->
9+
result = Lineup.format 'Maarten', 9
10+
expect(result).toEqual 'Maarten, you are the 9th customer we serve today. Thank you!'
11+
12+
xit 'format non-exceptional ordinal numeral 5', ->
13+
result = Lineup.format 'Petronila', 5
14+
expect(result).toEqual 'Petronila, you are the 5th customer we serve today. Thank you!'
15+
16+
xit 'format non-exceptional ordinal numeral 6', ->
17+
result = Lineup.format 'Attakullakulla', 6
18+
expect(result).toEqual 'Attakullakulla, you are the 6th customer we serve today. Thank you!'
19+
20+
xit 'format non-exceptional ordinal numeral 7', ->
21+
result = Lineup.format 'Kate', 7
22+
expect(result).toEqual 'Kate, you are the 7th customer we serve today. Thank you!'
23+
24+
xit 'format non-exceptional ordinal numeral 8', ->
25+
result = Lineup.format 'Maximiliano', 8
26+
expect(result).toEqual 'Maximiliano, you are the 8th customer we serve today. Thank you!'
27+
28+
xit 'format exceptional ordinal numeral 1', ->
29+
result = Lineup.format 'Mary', 1
30+
expect(result).toEqual 'Mary, you are the 1st customer we serve today. Thank you!'
31+
32+
xit 'format exceptional ordinal numeral 2', ->
33+
result = Lineup.format 'Haruto', 2
34+
expect(result).toEqual 'Haruto, you are the 2nd customer we serve today. Thank you!'
35+
36+
xit 'format exceptional ordinal numeral 3', ->
37+
result = Lineup.format 'Henriette', 3
38+
expect(result).toEqual 'Henriette, you are the 3rd customer we serve today. Thank you!'
39+
40+
xit 'format smallest two digit non-exceptional ordinal numeral 10', ->
41+
result = Lineup.format 'Alvarez', 10
42+
expect(result).toEqual 'Alvarez, you are the 10th customer we serve today. Thank you!'
43+
44+
xit 'format non-exceptional ordinal numeral 11', ->
45+
result = Lineup.format 'Jacqueline', 11
46+
expect(result).toEqual 'Jacqueline, you are the 11th customer we serve today. Thank you!'
47+
48+
xit 'format non-exceptional ordinal numeral 12', ->
49+
result = Lineup.format 'Juan', 12
50+
expect(result).toEqual 'Juan, you are the 12th customer we serve today. Thank you!'
51+
52+
xit 'format non-exceptional ordinal numeral 13', ->
53+
result = Lineup.format 'Patricia', 13
54+
expect(result).toEqual 'Patricia, you are the 13th customer we serve today. Thank you!'
55+
56+
xit 'format exceptional ordinal numeral 21', ->
57+
result = Lineup.format 'Washi', 21
58+
expect(result).toEqual 'Washi, you are the 21st customer we serve today. Thank you!'
59+
60+
xit 'format exceptional ordinal numeral 62', ->
61+
result = Lineup.format 'Nayra', 62
62+
expect(result).toEqual 'Nayra, you are the 62nd customer we serve today. Thank you!'
63+
64+
xit 'format exceptional ordinal numeral 100', ->
65+
result = Lineup.format 'John', 100
66+
expect(result).toEqual 'John, you are the 100th customer we serve today. Thank you!'
67+
68+
xit 'format exceptional ordinal numeral 101', ->
69+
result = Lineup.format 'Zeinab', 101
70+
expect(result).toEqual 'Zeinab, you are the 101st customer we serve today. Thank you!'
71+
72+
xit 'format non-exceptional ordinal numeral 112', ->
73+
result = Lineup.format 'Knud', 112
74+
expect(result).toEqual 'Knud, you are the 112th customer we serve today. Thank you!'
75+
76+
xit 'format exceptional ordinal numeral 123', ->
77+
result = Lineup.format 'Yma', 123
78+
expect(result).toEqual 'Yma, you are the 123rd customer we serve today. Thank you!'

0 commit comments

Comments
 (0)