Skip to content

Commit dacec9f

Browse files
add two-fer exercise
1 parent 4d8098f commit dacec9f

File tree

9 files changed

+112
-0
lines changed

9 files changed

+112
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Instructions
2+
3+
Your task is to determine what you will say as you give away the extra cookie.
4+
5+
If you know the person's name (e.g. if they're named Do-yun), then you will say:
6+
7+
```text
8+
One for Do-yun, one for me.
9+
```
10+
11+
If you don't know the person's name, you will say _you_ instead.
12+
13+
```text
14+
One for you, one for me.
15+
```
16+
17+
Here are some examples:
18+
19+
| Name | Dialogue |
20+
| :----- | :-------------------------- |
21+
| Alice | One for Alice, one for me. |
22+
| Bohdan | One for Bohdan, one for me. |
23+
| | One for you, one for me. |
24+
| Zaphod | One for Zaphod, one for me. |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Introduction
2+
3+
In some English accents, when you say "two for" quickly, it sounds like "two fer".
4+
Two-for-one is a way of saying that if you buy one, you also get one for free.
5+
So the phrase "two-fer" often implies a two-for-one offer.
6+
7+
Imagine a bakery that has a holiday offer where you can buy two cookies for the price of one ("two-fer one!").
8+
You take the offer and (very generously) decide to give the extra cookie to someone else in the queue.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let twoFer = name => {
2+
switch name {
3+
| None => "One for you, one for me."
4+
| Some(nameString) => "One for " ++ nameString ++ ", one for me."
5+
}
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"authors": [
3+
"tejasbubane",
4+
"therealowenrees"
5+
],
6+
"files": {
7+
"solution": [
8+
"src/TwoFer.res"
9+
],
10+
"test": [
11+
"tests/TwoFer_test.res"
12+
],
13+
"example": [
14+
".meta/TwoFer.res"
15+
],
16+
"editor": [
17+
"src/TwoFer.resi"
18+
]
19+
},
20+
"blurb": "Create a sentence of the form \"One for X, one for me.\".",
21+
"source_url": "https://github.com/exercism/problem-specifications/issues/757"
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
[1cf3e15a-a3d7-4a87-aeb3-ba1b43bc8dce]
13+
description = "no name given"
14+
15+
[b4c6dbb8-b4fb-42c2-bafd-10785abe7709]
16+
description = "a name given"
17+
18+
[3549048d-1a6e-4653-9a79-b0bda163e8d5]
19+
description = "another name given"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@exercism/rescript",
3+
"sources": [
4+
{ "dir": "src", "subdirs": true, "type": "dev" },
5+
{ "dir": "tests", "subdirs": true, "type": "dev" }
6+
],
7+
"package-specs": [
8+
{
9+
"module": "esmodule",
10+
"in-source": true
11+
}
12+
],
13+
"suffix": ".res.js",
14+
"dev-dependencies": ["rescript-test"]
15+
}

exercises/practice/two-fer/src/TwoFer.res

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let twoFer: option<string> => string
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
open Test
2+
open TwoFer
3+
4+
let stringEqual = (~message=?, a: string, b: string) => assertion(~message?, ~operator="stringEqual", (a, b) => a == b, a, b)
5+
6+
test("no name given", () => {
7+
stringEqual(~message="no name given", twoFer(None), "One for you, one for me.")
8+
})
9+
10+
test("a name given", () => {
11+
stringEqual(~message="a name given", twoFer(Some("Alice")), "One for Alice, one for me.")
12+
})
13+
14+
test("another name given", () => {
15+
stringEqual(~message="another name given", twoFer(Some("Bob")), "One for Bob, one for me.")
16+
})
17+

0 commit comments

Comments
 (0)