Skip to content

Commit 74b6fba

Browse files
committed
Add more solutions
1 parent 1cf2cc5 commit 74b6fba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+67554
-3
lines changed

Diff for: README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,18 @@ This repository is created to track my learning progress, and I will constantly
5555

5656
### Other exercises
5757
- Easy
58-
- [Two fer](javascript/two-fer)
59-
- [Resistor color](javascript/resistor-color)
60-
58+
- [Two Fer](javascript/two-fer)
59+
- [Resistor Color](javascript/resistor-color)
60+
- [Resistor Color Duo](javascript/resistor-color-duo)
61+
- [Gigasecond](javascript/gigasecond)
62+
- [RNA Transcription](javascript/rna-transcription)
63+
- [Space Age](javascript/space-age)
64+
- [Pangram](javascript/pangram)
65+
- [Matrix](javascript/matrix)
66+
67+
- Medium
68+
- [Bob](javascript/bob)
69+
6170
6271
More to come...
6372
## Exercise profile

Diff for: javascript/bob/.eslintrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"root": true,
3+
"extends": "@exercism/eslint-config-javascript",
4+
"env": {
5+
"jest": true
6+
},
7+
"overrides": [
8+
{
9+
"files": [".meta/proof.ci.js", ".meta/exemplar.js", "*.spec.js"],
10+
"excludedFiles": ["custom.spec.js"],
11+
"extends": "@exercism/eslint-config-javascript/maintainers"
12+
}
13+
]
14+
}

Diff for: javascript/bob/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
audit=false

Diff for: javascript/bob/HELP.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Help
2+
3+
## Running the tests
4+
5+
## Setup
6+
7+
Go through the setup [instructions for JavaScript][docs-exercism-javascript] to install the necessary dependencies.
8+
9+
## Requirements
10+
11+
Install assignment dependencies:
12+
13+
```shell
14+
# Using npm
15+
npm install
16+
17+
# Alternatively using yarn
18+
yarn
19+
```
20+
21+
## Making the test suite pass
22+
23+
All exercises come with a test suite to help you validate your solution before submitting.
24+
You can execute these tests by opening a command prompt in the exercise's directory, and then running:
25+
26+
```bash
27+
# Using npm
28+
npm test
29+
30+
# Alternatively using yarn
31+
yarn test
32+
```
33+
34+
In some test suites all tests but the first have been skipped.
35+
36+
Once you get a test passing, you can enable the next one by changing `xtest` to `test`.
37+
38+
## Writing custom tests
39+
40+
If you wish to write additional, custom, tests, create a new file `custom.spec.js`, and submit it with your solution together with the new file:
41+
42+
```shell
43+
exercism submit numbers.js custom.spec.js
44+
```
45+
46+
[docs-exercism-javascript]: https://exercism.org/docs/tracks/javascript/installation
47+
48+
## Submitting your solution
49+
50+
You can submit your solution using the `exercism submit bob.js` command.
51+
This command will upload your solution to the Exercism website and print the solution page's URL.
52+
53+
It's possible to submit an incomplete solution which allows you to:
54+
55+
- See how others have completed the exercise
56+
- Request help from a mentor
57+
58+
## Need to get help?
59+
60+
If you'd like help solving the exercise, check the following pages:
61+
62+
- The [JavaScript track's documentation](https://exercism.org/docs/tracks/javascript)
63+
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
64+
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
65+
66+
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
67+
68+
To get help if you're having trouble, you can use one of the following resources:
69+
70+
- [Gitter](https://gitter.im/exercism/support) is Exercism's Gitter room; go here to get support and ask questions if you face any issues with downloading or submitting your exercises.
71+
- [/r/javascript](https://www.reddit.com/r/javascript) is the Javascript subreddit.
72+
- [StackOverflow](https://stackoverflow.com/questions/tagged/javascript+exercism) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
73+
- [Github issue tracker](https://github.com/exercism/javascript/issues) is where we track our development and maintainance of Javascript exercises in exercism. But if none of the above links help you, feel free to post an issue here.

Diff for: javascript/bob/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Bob
2+
3+
Welcome to Bob on Exercism's JavaScript Track.
4+
If you need help running the tests or submitting your code, check out `HELP.md`.
5+
6+
## Instructions
7+
8+
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
9+
10+
Bob answers 'Sure.' if you ask him a question, such as "How are you?".
11+
12+
He answers 'Whoa, chill out!' if you YELL AT HIM (in all capitals).
13+
14+
He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
15+
16+
He says 'Fine. Be that way!' if you address him without actually saying
17+
anything.
18+
19+
He answers 'Whatever.' to anything else.
20+
21+
Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.
22+
23+
## Source
24+
25+
### Created by
26+
27+
- @rchavarria
28+
29+
### Contributed to by
30+
31+
- @amscotti
32+
- @austinratcliff
33+
- @brendan-c
34+
- @draalger
35+
- @hayashi-ay
36+
- @kytrinyx
37+
- @matthewmorgan
38+
- @ryanplusplus
39+
- @serixscorpio
40+
- @SleeplessByte
41+
- @xarxziux
42+
43+
### Based on
44+
45+
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. - http://pine.fm/LearnToProgram/?Chapter=06

Diff for: javascript/bob/babel.config.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 'current',
8+
},
9+
useBuiltIns: 'entry',
10+
corejs: '3.17',
11+
},
12+
],
13+
],
14+
plugins: ['@babel/plugin-syntax-bigint'],
15+
};

Diff for: javascript/bob/bob.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// This is only a SKELETON file for the 'Bob' exercise. It's been provided as a
3+
// convenience to get you started writing code faster.
4+
//
5+
6+
const HAS_YELL_POSSIBILITY = /[A-Z]/;
7+
const YELL_EXPRESSION = /^[^a-z]+$/g;
8+
const YELL_WITH_QUESITON_EXPRESSION = /^[^(a-z?)]+\?$/g;
9+
const NO_EXPRESSION = /^$|^[\s]+$/g;
10+
11+
export const hey = message => {
12+
if (message.match(NO_EXPRESSION)) return "Fine. Be that way!";
13+
14+
if (message.match(HAS_YELL_POSSIBILITY)) {
15+
if (message.match(YELL_WITH_QUESITON_EXPRESSION))
16+
return "Calm down, I know what I'm doing!";
17+
18+
if (message.match(YELL_EXPRESSION)) return "Whoa, chill out!";
19+
}
20+
if (message.trim().charAt(message.trim().length - 1) === "?") return "Sure.";
21+
22+
return "Whatever.";
23+
};

Diff for: javascript/bob/bob.spec.js

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import { hey } from './bob';
2+
3+
describe('Bob', () => {
4+
test('stating something', () => {
5+
const result = hey('Tom-ay-to, tom-aaaah-to.');
6+
expect(result).toEqual('Whatever.');
7+
});
8+
9+
test('shouting', () => {
10+
const result = hey('WATCH OUT!');
11+
expect(result).toEqual('Whoa, chill out!');
12+
});
13+
14+
test('shouting gibberish', () => {
15+
const result = hey('FCECDFCAAB');
16+
expect(result).toEqual('Whoa, chill out!');
17+
});
18+
19+
test('asking a question', () => {
20+
const result = hey('Does this cryogenic chamber make me look fat?');
21+
expect(result).toEqual('Sure.');
22+
});
23+
24+
test('asking a numeric question', () => {
25+
const result = hey('You are, what, like 15?');
26+
expect(result).toEqual('Sure.');
27+
});
28+
29+
test('asking gibberish', () => {
30+
const result = hey('fffbbcbeab?');
31+
expect(result).toEqual('Sure.');
32+
});
33+
34+
test('talking forcefully', () => {
35+
const result = hey("Let's go make out behind the gym!");
36+
expect(result).toEqual('Whatever.');
37+
});
38+
39+
test('using acronyms in regular speech', () => {
40+
const result = hey("It's OK if you don't want to go to the DMV.");
41+
expect(result).toEqual('Whatever.');
42+
});
43+
44+
test('forceful question', () => {
45+
const result = hey('WHAT THE HELL WERE YOU THINKING?');
46+
expect(result).toEqual("Calm down, I know what I'm doing!");
47+
});
48+
49+
test('shouting numbers', () => {
50+
const result = hey('1, 2, 3 GO!');
51+
expect(result).toEqual('Whoa, chill out!');
52+
});
53+
54+
test('no letters', () => {
55+
const result = hey('1, 2, 3');
56+
expect(result).toEqual('Whatever.');
57+
});
58+
59+
test('question with no letters', () => {
60+
const result = hey('4?');
61+
expect(result).toEqual('Sure.');
62+
});
63+
64+
test('shouting with special characters', () => {
65+
const result = hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!');
66+
expect(result).toEqual('Whoa, chill out!');
67+
});
68+
69+
test('shouting with no exclamation mark', () => {
70+
const result = hey('I HATE YOU');
71+
expect(result).toEqual('Whoa, chill out!');
72+
});
73+
74+
test('statement containing question mark', () => {
75+
const result = hey('Ending with a ? means a question.');
76+
expect(result).toEqual('Whatever.');
77+
});
78+
79+
test('non-letters with question', () => {
80+
const result = hey(':) ?');
81+
expect(result).toEqual('Sure.');
82+
});
83+
84+
test('prattling on', () => {
85+
const result = hey('Wait! Hang on. Are you going to be OK?');
86+
expect(result).toEqual('Sure.');
87+
});
88+
89+
test('silence', () => {
90+
const result = hey('');
91+
expect(result).toEqual('Fine. Be that way!');
92+
});
93+
94+
test('prolonged silence', () => {
95+
const result = hey(' ');
96+
expect(result).toEqual('Fine. Be that way!');
97+
});
98+
99+
test('alternate silence', () => {
100+
const result = hey('\t\t\t\t\t\t\t\t\t\t');
101+
expect(result).toEqual('Fine. Be that way!');
102+
});
103+
104+
test('multiple line question', () => {
105+
const result = hey('\nDoes this cryogenic chamber make me look fat?\nno');
106+
expect(result).toEqual('Whatever.');
107+
});
108+
109+
test('starting with whitespace', () => {
110+
const result = hey(' hmmmmmmm...');
111+
expect(result).toEqual('Whatever.');
112+
});
113+
114+
test('ending with whitespace', () => {
115+
const result = hey('Okay if like my spacebar quite a bit? ');
116+
expect(result).toEqual('Sure.');
117+
});
118+
119+
test('other whitespace', () => {
120+
const result = hey('\n\r \t');
121+
expect(result).toEqual('Fine. Be that way!');
122+
});
123+
124+
test('non-question ending with whitespace', () => {
125+
const result = hey('This is a statement ending with whitespace ');
126+
expect(result).toEqual('Whatever.');
127+
});
128+
});

0 commit comments

Comments
 (0)