Skip to content

Commit da7a28d

Browse files
committed
Migrate word-count to ReScript
1 parent 888bca2 commit da7a28d

File tree

12 files changed

+1173
-4456
lines changed

12 files changed

+1173
-4456
lines changed

exercises/practice/word-count/.meta/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
],
1313
"files": {
1414
"solution": [
15-
"src/WordCount.re"
15+
"src/WordCount.res"
1616
],
1717
"test": [
18-
"__tests__/WordCount_test.re"
18+
"__tests__/WordCount_test.res"
1919
],
2020
"example": [
21-
".meta/src/Example.re"
21+
".meta/src/WordCount.res"
2222
]
2323
},
2424
"source": "This is a classic toy problem, but we were reminded of it by seeing it in the Go Tour."

exercises/practice/word-count/.meta/src/Example.re

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
let wordCount = (input: string) =>
2+
input
3+
->Js.String2.toLowerCase
4+
->Js.String2.replaceByRe(%re("/[^'a-zA-Z0-9]+/g"), " ")
5+
->Js.String2.trim
6+
->Js.String2.splitByRe(%re("/'?\\s+'?/"))
7+
->Js.Array2.map(Belt.Option.getExn)
8+
->Js.Array2.reduce((dict, word) => {
9+
let count = Js.Dict.get(dict, word)
10+
11+
switch count {
12+
| Some(value) => Js.Dict.set(dict, word, value + 1)
13+
| None => Js.Dict.set(dict, word, 1)
14+
}
15+
16+
dict
17+
}, Js.Dict.empty())
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Exercism
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

exercises/practice/word-count/__tests__/WordCount_test.re

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
1-
// This is the configuration file used by BuckleScript's build system bsb. Its documentation lives here: http://bucklescript.github.io/bucklescript/docson/#build-schema.json
2-
// BuckleScript comes with its own parser for bsconfig.json, which is normal JSON, with the extra support of comments and trailing commas.
31
{
4-
"name": "word-count",
5-
"version": "0.1.0",
2+
"name": "@exercism/rescript-word-count",
63
"sources": [
4+
{ "dir": "src", "subdirs": true },
5+
{ "dir": "tests", "subdirs": true, "type": "dev" }
6+
],
7+
"package-specs": [
78
{
8-
"dir": "src",
9-
"subdirs": true
10-
},
11-
{
12-
"dir": "__tests__",
13-
"type": "dev"
9+
"module": "es6-global",
10+
"in-source": true
1411
}
1512
],
16-
"package-specs": {
17-
"module": "commonjs",
18-
"in-source": true
19-
},
20-
"suffix": ".bs.js",
21-
"bs-dependencies": [
22-
// add your dependencies here. You'd usually install them normally through `npm install my-dependency`. If my-dependency has a bsconfig.json too, then everything will work seamlessly.
23-
],
24-
"bs-dev-dependencies": ["@glennsl/bs-jest"],
25-
"warnings": {
26-
"error": "+101"
27-
},
28-
"namespace": true,
29-
"refmt": 3
13+
"suffix": ".mjs",
14+
"bs-dev-dependencies": [
15+
"rescript-test"
16+
]
3017
}

0 commit comments

Comments
 (0)