From 2b42d3aaf1e9c8688142ce0e957e95b245e0dedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Mon, 13 Oct 2025 21:48:53 -0700 Subject: [PATCH] Add `line-up` exercise --- config.json | 8 ++ .../practice/line-up/.docs/instructions.md | 19 +++++ .../practice/line-up/.docs/introduction.md | 7 ++ exercises/practice/line-up/.meta/config.json | 19 +++++ .../practice/line-up/.meta/example.coffee | 20 +++++ exercises/practice/line-up/.meta/tests.toml | 67 ++++++++++++++++ exercises/practice/line-up/line-up.coffee | 4 + .../practice/line-up/line-up.spec.coffee | 78 +++++++++++++++++++ 8 files changed, 222 insertions(+) create mode 100644 exercises/practice/line-up/.docs/instructions.md create mode 100644 exercises/practice/line-up/.docs/introduction.md create mode 100644 exercises/practice/line-up/.meta/config.json create mode 100644 exercises/practice/line-up/.meta/example.coffee create mode 100644 exercises/practice/line-up/.meta/tests.toml create mode 100644 exercises/practice/line-up/line-up.coffee create mode 100644 exercises/practice/line-up/line-up.spec.coffee diff --git a/config.json b/config.json index c2934dc..50f13c8 100644 --- a/config.json +++ b/config.json @@ -285,6 +285,14 @@ "prerequisites": [], "difficulty": 2 }, + { + "slug": "line-up", + "name": "Line Up", + "uuid": "e73766c8-49bc-46ae-a814-630f02cb0d60", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, { "slug": "linked-list", "name": "Linked List", diff --git a/exercises/practice/line-up/.docs/instructions.md b/exercises/practice/line-up/.docs/instructions.md new file mode 100644 index 0000000..fb41d4c --- /dev/null +++ b/exercises/practice/line-up/.docs/instructions.md @@ -0,0 +1,19 @@ +# Instructions + +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]. +Yaʻqūb expects to use numbers from 1 up to 999. + +Rules: + +- Numbers ending in 1 (except for 11) → `"st"` +- Numbers ending in 2 (except for 12) → `"nd"` +- Numbers ending in 3 (except for 13) → `"rd"` +- All other numbers → `"th"` + +Examples: + +- `"Mary", 1` → `"Mary, you are the 1st customer we serve today. Thank you!"` +- `"John", 12` → `"John, you are the 12th customer we serve today. Thank you!"` +- `"Dahir", 162` → `"Dahir, you are the 162nd customer we serve today. Thank you!"` + +[ordinal-numeral]: https://en.wikipedia.org/wiki/Ordinal_numeral diff --git a/exercises/practice/line-up/.docs/introduction.md b/exercises/practice/line-up/.docs/introduction.md new file mode 100644 index 0000000..ea07268 --- /dev/null +++ b/exercises/practice/line-up/.docs/introduction.md @@ -0,0 +1,7 @@ +# Introduction + +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. +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. + +To make the customers feel special, he does not want the ticket to have only a number on it. +They shall get a proper English sentence with their name and number on it. diff --git a/exercises/practice/line-up/.meta/config.json b/exercises/practice/line-up/.meta/config.json new file mode 100644 index 0000000..3912afa --- /dev/null +++ b/exercises/practice/line-up/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "line-up.coffee" + ], + "test": [ + "line-up.spec.coffee" + ], + "example": [ + ".meta/example.coffee" + ] + }, + "blurb": "Help lining up customers at Yaʻqūb's Deli.", + "source": "mk-mxp, based on previous work from Exercism contributors codedge and neenjaw", + "source_url": "https://forum.exercism.org/t/new-exercise-ordinal-numbers/19147" +} diff --git a/exercises/practice/line-up/.meta/example.coffee b/exercises/practice/line-up/.meta/example.coffee new file mode 100644 index 0000000..47e2af5 --- /dev/null +++ b/exercises/practice/line-up/.meta/example.coffee @@ -0,0 +1,20 @@ +class Lineup + @format: (name, number) -> + suffix = @getSuffix number + "#{name}, you are the #{number}#{suffix} customer we serve today. Thank you!" + + @getSuffix: (number) -> + mod100 = number % 100 + mod10 = number % 10 + if mod100 in [11, 12, 13] + 'th' + else if mod10 is 1 + 'st' + else if mod10 is 2 + 'nd' + else if mod10 is 3 + 'rd' + else + 'th' + +module.exports = Lineup diff --git a/exercises/practice/line-up/.meta/tests.toml b/exercises/practice/line-up/.meta/tests.toml new file mode 100644 index 0000000..36fdf1d --- /dev/null +++ b/exercises/practice/line-up/.meta/tests.toml @@ -0,0 +1,67 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[7760d1b8-4864-4db4-953b-0fa7c047dbc0] +description = "format smallest non-exceptional ordinal numeral 4" + +[e8b7c715-6baa-4f7b-8fb3-2fa48044ab7a] +description = "format greatest single digit non-exceptional ordinal numeral 9" + +[f370aae9-7ae7-4247-90ce-e8ff8c6934df] +description = "format non-exceptional ordinal numeral 5" + +[37f10dea-42a2-49de-bb92-0b690b677908] +description = "format non-exceptional ordinal numeral 6" + +[d8dfb9a2-3a1f-4fee-9dae-01af3600054e] +description = "format non-exceptional ordinal numeral 7" + +[505ec372-1803-42b1-9377-6934890fd055] +description = "format non-exceptional ordinal numeral 8" + +[8267072d-be1f-4f70-b34a-76b7557a47b9] +description = "format exceptional ordinal numeral 1" + +[4d8753cb-0364-4b29-84b8-4374a4fa2e3f] +description = "format exceptional ordinal numeral 2" + +[8d44c223-3a7e-4f48-a0ca-78e67bf98aa7] +description = "format exceptional ordinal numeral 3" + +[6c4f6c88-b306-4f40-bc78-97cdd583c21a] +description = "format smallest two digit non-exceptional ordinal numeral 10" + +[e257a43f-d2b1-457a-97df-25f0923fc62a] +description = "format non-exceptional ordinal numeral 11" + +[bb1db695-4d64-457f-81b8-4f5a2107e3f4] +description = "format non-exceptional ordinal numeral 12" + +[60a3187c-9403-4835-97de-4f10ebfd63e2] +description = "format non-exceptional ordinal numeral 13" + +[2bdcebc5-c029-4874-b6cc-e9bec80d603a] +description = "format exceptional ordinal numeral 21" + +[74ee2317-0295-49d2-baf0-d56bcefa14e3] +description = "format exceptional ordinal numeral 62" + +[b37c332d-7f68-40e3-8503-e43cbd67a0c4] +description = "format exceptional ordinal numeral 100" + +[0375f250-ce92-4195-9555-00e28ccc4d99] +description = "format exceptional ordinal numeral 101" + +[0d8a4974-9a8a-45a4-aca7-a9fb473c9836] +description = "format non-exceptional ordinal numeral 112" + +[06b62efe-199e-4ce7-970d-4bf73945713f] +description = "format exceptional ordinal numeral 123" diff --git a/exercises/practice/line-up/line-up.coffee b/exercises/practice/line-up/line-up.coffee new file mode 100644 index 0000000..274076c --- /dev/null +++ b/exercises/practice/line-up/line-up.coffee @@ -0,0 +1,4 @@ +class Lineup + @format: (name, number) -> + +module.exports = Lineup diff --git a/exercises/practice/line-up/line-up.spec.coffee b/exercises/practice/line-up/line-up.spec.coffee new file mode 100644 index 0000000..caa8b3e --- /dev/null +++ b/exercises/practice/line-up/line-up.spec.coffee @@ -0,0 +1,78 @@ +Lineup = require './line-up' + +describe 'Lineup', -> + it 'format smallest non-exceptional ordinal numeral 4', -> + result = Lineup.format 'Gianna', 4 + expect(result).toEqual 'Gianna, you are the 4th customer we serve today. Thank you!' + + xit 'format greatest single digit non-exceptional ordinal numeral 9', -> + result = Lineup.format 'Maarten', 9 + expect(result).toEqual 'Maarten, you are the 9th customer we serve today. Thank you!' + + xit 'format non-exceptional ordinal numeral 5', -> + result = Lineup.format 'Petronila', 5 + expect(result).toEqual 'Petronila, you are the 5th customer we serve today. Thank you!' + + xit 'format non-exceptional ordinal numeral 6', -> + result = Lineup.format 'Attakullakulla', 6 + expect(result).toEqual 'Attakullakulla, you are the 6th customer we serve today. Thank you!' + + xit 'format non-exceptional ordinal numeral 7', -> + result = Lineup.format 'Kate', 7 + expect(result).toEqual 'Kate, you are the 7th customer we serve today. Thank you!' + + xit 'format non-exceptional ordinal numeral 8', -> + result = Lineup.format 'Maximiliano', 8 + expect(result).toEqual 'Maximiliano, you are the 8th customer we serve today. Thank you!' + + xit 'format exceptional ordinal numeral 1', -> + result = Lineup.format 'Mary', 1 + expect(result).toEqual 'Mary, you are the 1st customer we serve today. Thank you!' + + xit 'format exceptional ordinal numeral 2', -> + result = Lineup.format 'Haruto', 2 + expect(result).toEqual 'Haruto, you are the 2nd customer we serve today. Thank you!' + + xit 'format exceptional ordinal numeral 3', -> + result = Lineup.format 'Henriette', 3 + expect(result).toEqual 'Henriette, you are the 3rd customer we serve today. Thank you!' + + xit 'format smallest two digit non-exceptional ordinal numeral 10', -> + result = Lineup.format 'Alvarez', 10 + expect(result).toEqual 'Alvarez, you are the 10th customer we serve today. Thank you!' + + xit 'format non-exceptional ordinal numeral 11', -> + result = Lineup.format 'Jacqueline', 11 + expect(result).toEqual 'Jacqueline, you are the 11th customer we serve today. Thank you!' + + xit 'format non-exceptional ordinal numeral 12', -> + result = Lineup.format 'Juan', 12 + expect(result).toEqual 'Juan, you are the 12th customer we serve today. Thank you!' + + xit 'format non-exceptional ordinal numeral 13', -> + result = Lineup.format 'Patricia', 13 + expect(result).toEqual 'Patricia, you are the 13th customer we serve today. Thank you!' + + xit 'format exceptional ordinal numeral 21', -> + result = Lineup.format 'Washi', 21 + expect(result).toEqual 'Washi, you are the 21st customer we serve today. Thank you!' + + xit 'format exceptional ordinal numeral 62', -> + result = Lineup.format 'Nayra', 62 + expect(result).toEqual 'Nayra, you are the 62nd customer we serve today. Thank you!' + + xit 'format exceptional ordinal numeral 100', -> + result = Lineup.format 'John', 100 + expect(result).toEqual 'John, you are the 100th customer we serve today. Thank you!' + + xit 'format exceptional ordinal numeral 101', -> + result = Lineup.format 'Zeinab', 101 + expect(result).toEqual 'Zeinab, you are the 101st customer we serve today. Thank you!' + + xit 'format non-exceptional ordinal numeral 112', -> + result = Lineup.format 'Knud', 112 + expect(result).toEqual 'Knud, you are the 112th customer we serve today. Thank you!' + + xit 'format exceptional ordinal numeral 123', -> + result = Lineup.format 'Yma', 123 + expect(result).toEqual 'Yma, you are the 123rd customer we serve today. Thank you!'