Skip to content

Commit

Permalink
publish week 17
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanous committed Apr 28, 2021
1 parent bf9b145 commit 8e623a1
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
32 changes: 32 additions & 0 deletions 2021/w17/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Week 17 challenge

You have joined a team which works on a new programming language. The language is intended to be functional lisp-like.
So a lot of parenthesis in the syntax.

You pick up the task to write utility for the parser, which will simply validate if in given string the parenthesis are valid.
E.g. are they wrapping and closing properly.

This function should only look at parenthesis and, thus, ignore any other characters that might be in it.


Examples:
```
isValid('fn(1, 2, 3)') // returns true
isValid('!)()()') // return false
isValid('()') // returns true
isValid('())') // returns false
isValid('(()(()))') // returns true
isValid(')(()(()))') // returns false
isValid('((777))(((arg)())(...rest))') // returns true
isValid('((777))((...args)())(9))') // returns false
```


## Upload link

[https://forms.gle/N4rY73sULh3prw96A]


## Results

7 changes: 7 additions & 0 deletions 2021/w17/solutions/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const isValid = (code) => {
// your solution here

return undefined;
};

module.exports = isValid;
1 change: 1 addition & 0 deletions 2021/w17/test-cases/spec.json

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions 2021/w17/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const fs = require("fs");
const path = require("path");
const spec = require("./test-cases/spec.json");
const solutions = fs.readdirSync(path.resolve(__dirname, "solutions"));

describe.each(solutions)("%s", (filename) => {
const evaluate = require(path.resolve(__dirname, "solutions", filename));
test.each([
['n(1, 2, 3)', true],
['!)()()', false],
['()', true],
['())', false],
['(()(()))', true],
[')(()(()))', false],
['((777))(((arg)())(...rest))', true],
['((777))((...args)())(9))', false],
])("%j = %j", (input, result) => {
expect(evaluate(input)).toBe(result);
});

test.each(spec.map(({ inputs, result }) => [inputs[0], result]))(
"%j = %j",
(input, result) => {
expect(evaluate(input)).toBe(result);
}
);
});
2 changes: 1 addition & 1 deletion evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { table } = require('table');
const humanizeDuration = require('humanize-duration');

// update for challenge you wish to evaluate, what is the tie margin and amount of default runs
const CHALLENGE = '2021/w16';
const CHALLENGE = '2021/w17';
const PERCENT_MARGIN_FOR_TIE = 5;
const TIMES_TO_EVAL_EACH = parseInt(process.argv[2], 10) || 1000;
const LOG_PAD = 35;
Expand Down

0 comments on commit 8e623a1

Please sign in to comment.