Skip to content

Commit

Permalink
Migrage word-count to ReScript
Browse files Browse the repository at this point in the history
  • Loading branch information
JsonKim committed Aug 2, 2022
1 parent 888bca2 commit 3d58fd7
Show file tree
Hide file tree
Showing 12 changed files with 1,173 additions and 4,456 deletions.
6 changes: 3 additions & 3 deletions exercises/practice/word-count/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
],
"files": {
"solution": [
"src/WordCount.re"
"src/WordCount.res"
],
"test": [
"__tests__/WordCount_test.re"
"__tests__/WordCount_test.res"
],
"example": [
".meta/src/Example.re"
".meta/src/WordCount.res"
]
},
"source": "This is a classic toy problem, but we were reminded of it by seeing it in the Go Tour."
Expand Down
20 changes: 0 additions & 20 deletions exercises/practice/word-count/.meta/src/Example.re

This file was deleted.

17 changes: 17 additions & 0 deletions exercises/practice/word-count/.meta/src/WordCount.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let wordCount = (input: string) =>
input
->Js.String2.toLowerCase
->Js.String2.replaceByRe(%re("/[^'a-zA-Z0-9]+/g"), " ")
->Js.String2.trim
->Js.String2.splitByRe(%re("/'?\\s+'?/"))
->Js.Array2.map(Belt.Option.getExn)
->Js.Array2.reduce((dict, word) => {
let count = Js.Dict.get(dict, word)

switch count {
| Some(value) => Js.Dict.set(dict, word, value + 1)
| None => Js.Dict.set(dict, word, 1)
}

dict
}, Js.Dict.empty())
21 changes: 21 additions & 0 deletions exercises/practice/word-count/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Exercism

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
79 changes: 0 additions & 79 deletions exercises/practice/word-count/__tests__/WordCount_test.re

This file was deleted.

35 changes: 11 additions & 24 deletions exercises/practice/word-count/bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
// 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
// BuckleScript comes with its own parser for bsconfig.json, which is normal JSON, with the extra support of comments and trailing commas.
{
"name": "word-count",
"version": "0.1.0",
"name": "@exercism/rescript-word-count",
"sources": [
{ "dir": "src", "subdirs": true },
{ "dir": "tests", "subdirs": true, "type": "dev" }
],
"package-specs": [
{
"dir": "src",
"subdirs": true
},
{
"dir": "__tests__",
"type": "dev"
"module": "es6-global",
"in-source": true
}
],
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
// 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.
],
"bs-dev-dependencies": ["@glennsl/bs-jest"],
"warnings": {
"error": "+101"
},
"namespace": true,
"refmt": 3
"suffix": ".mjs",
"bs-dev-dependencies": [
"rescript-test"
]
}
Loading

0 comments on commit 3d58fd7

Please sign in to comment.