summary refs log tree commit diff stats
path: root/javascript/raindrops
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-03 18:18:33 +0530
committerAndinus <andinus@nand.sh>2021-09-03 18:18:33 +0530
commit9cec9e1815f3da2da02173b5302b372a761df00f (patch)
treededfd040e6d5d3a7c313a543b9df2aacc1ca904d /javascript/raindrops
parentcbc991d678e6c7ee84471c7c6561a6084bb85ccd (diff)
downloadexercism-9cec9e1815f3da2da02173b5302b372a761df00f.tar.gz
JS: Raindrops: Add solution
Diffstat (limited to 'javascript/raindrops')
-rw-r--r--javascript/raindrops/.eslintrc14
-rw-r--r--javascript/raindrops/.npmrc1
-rw-r--r--javascript/raindrops/HELP.md73
-rw-r--r--javascript/raindrops/LICENSE21
-rw-r--r--javascript/raindrops/README.md41
-rw-r--r--javascript/raindrops/babel.config.js15
-rw-r--r--javascript/raindrops/package.json31
-rw-r--r--javascript/raindrops/raindrops.js11
-rw-r--r--javascript/raindrops/raindrops.spec.js52
9 files changed, 259 insertions, 0 deletions
diff --git a/javascript/raindrops/.eslintrc b/javascript/raindrops/.eslintrc
new file mode 100644
index 0000000..1d44460
--- /dev/null
+++ b/javascript/raindrops/.eslintrc
@@ -0,0 +1,14 @@
+{
+  "root": true,
+  "extends": "@exercism/eslint-config-javascript",
+  "env": {
+    "jest": true
+  },
+  "overrides": [
+    {
+      "files": [".meta/proof.ci.js", ".meta/exemplar.js", "*.spec.js"],
+      "excludedFiles": ["custom.spec.js"],
+      "extends": "@exercism/eslint-config-javascript/maintainers"
+    }
+  ]
+}
diff --git a/javascript/raindrops/.npmrc b/javascript/raindrops/.npmrc
new file mode 100644
index 0000000..d26df80
--- /dev/null
+++ b/javascript/raindrops/.npmrc
@@ -0,0 +1 @@
+audit=false
diff --git a/javascript/raindrops/HELP.md b/javascript/raindrops/HELP.md
new file mode 100644
index 0000000..1f95812
--- /dev/null
+++ b/javascript/raindrops/HELP.md
@@ -0,0 +1,73 @@
+# Help
+
+## Running the tests
+
+## Setup
+
+Go through the setup [instructions for JavaScript][docs-exercism-javascript] to install the necessary dependencies.
+
+## Requirements
+
+Install assignment dependencies:
+
+```shell
+# Using npm
+npm install
+
+# Alternatively using yarn
+yarn
+```
+
+## Making the test suite pass
+
+All exercises come with a test suite to help you validate your solution before submitting.
+You can execute these tests by opening a command prompt in the exercise's directory, and then running:
+
+```bash
+# Using npm
+npm test
+
+# Alternatively using yarn
+yarn test
+```
+
+In some test suites all tests but the first have been skipped.
+
+Once you get a test passing, you can enable the next one by changing `xtest` to `test`.
+
+## Writing custom tests
+
+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:
+
+```shell
+exercism submit numbers.js custom.spec.js
+```
+
+[docs-exercism-javascript]: https://exercism.io/tracks/javascript/installation
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit raindrops.js` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [JavaScript track's documentation](https://exercism.org/docs/tracks/javascript)
+- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [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.
+- [/r/javascript](https://www.reddit.com/r/javascript) is the Javascript subreddit.
+- [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.
+- [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.
\ No newline at end of file
diff --git a/javascript/raindrops/LICENSE b/javascript/raindrops/LICENSE
new file mode 100644
index 0000000..90e73be
--- /dev/null
+++ b/javascript/raindrops/LICENSE
@@ -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.
diff --git a/javascript/raindrops/README.md b/javascript/raindrops/README.md
new file mode 100644
index 0000000..bc08f4e
--- /dev/null
+++ b/javascript/raindrops/README.md
@@ -0,0 +1,41 @@
+# Raindrops
+
+Welcome to Raindrops on Exercism's JavaScript Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Your task is to convert a number into a string that contains raindrop sounds corresponding to certain potential factors. A factor is a number that evenly divides into another number, leaving no remainder. The simplest way to test if a one number is a factor of another is to use the [modulo operation](https://en.wikipedia.org/wiki/Modulo_operation).
+
+The rules of `raindrops` are that if a given number:
+
+- has 3 as a factor, add 'Pling' to the result.
+- has 5 as a factor, add 'Plang' to the result.
+- has 7 as a factor, add 'Plong' to the result.
+- _does not_ have any of 3, 5, or 7 as a factor, the result should be the digits of the number.
+
+## Examples
+
+- 28 has 7 as a factor, but not 3 or 5, so the result would be "Plong".
+- 30 has both 3 and 5 as factors, but not 7, so the result would be "PlingPlang".
+- 34 is not factored by 3, 5, or 7, so the result would be "34".
+
+## Source
+
+### Created by
+
+- @matthewmorgan
+
+### Contributed to by
+
+- @ankorGH
+- @cmccandless
+- @JesseSingleton
+- @ovidiu141
+- @rchavarria
+- @ryanplusplus
+- @SleeplessByte
+
+### Based on
+
+A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division. - https://en.wikipedia.org/wiki/Fizz_buzz
\ No newline at end of file
diff --git a/javascript/raindrops/babel.config.js b/javascript/raindrops/babel.config.js
new file mode 100644
index 0000000..7940aa0
--- /dev/null
+++ b/javascript/raindrops/babel.config.js
@@ -0,0 +1,15 @@
+module.exports = {
+  presets: [
+    [
+      '@babel/preset-env',
+      {
+        targets: {
+          node: 'current',
+        },
+        useBuiltIns: 'entry',
+        corejs: '3.14',
+      },
+    ],
+  ],
+  plugins: ['@babel/plugin-syntax-bigint'],
+};
diff --git a/javascript/raindrops/package.json b/javascript/raindrops/package.json
new file mode 100644
index 0000000..3d6722c
--- /dev/null
+++ b/javascript/raindrops/package.json
@@ -0,0 +1,31 @@
+{
+  "name": "@exercism/javascript-raindrops",
+  "description": "Exercism exercises in Javascript.",
+  "author": "Katrina Owen",
+  "private": true,
+  "license": "MIT",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/exercism/javascript",
+    "directory": "exercises/practice/raindrops"
+  },
+  "devDependencies": {
+    "@babel/cli": "^7.14.8",
+    "@babel/core": "^7.15.4",
+    "@babel/plugin-syntax-bigint": "^7.8.3",
+    "@babel/preset-env": "^7.15.0",
+    "@exercism/eslint-config-javascript": "^0.4.0",
+    "@types/jest": "^27.0.1",
+    "@types/node": "^16.7.10",
+    "babel-jest": "^27.1.0",
+    "core-js": "^3.17.1",
+    "eslint": "^7.32.0",
+    "jest": "^26.6.3"
+  },
+  "dependencies": {},
+  "scripts": {
+    "test": "jest --no-cache ./*",
+    "watch": "jest --no-cache --watch ./*",
+    "lint": "eslint ."
+  }
+}
diff --git a/javascript/raindrops/raindrops.js b/javascript/raindrops/raindrops.js
new file mode 100644
index 0000000..f8dff04
--- /dev/null
+++ b/javascript/raindrops/raindrops.js
@@ -0,0 +1,11 @@
+'use strict';
+
+export const convert = (num) => {
+    let drops = "";
+    if (num % 3 == 0) drops += "Pling";
+    if (num % 5 == 0) drops += "Plang";
+    if (num % 7 == 0) drops += "Plong";
+
+    if (drops.length == 0) drops += num;
+    return drops;
+};
diff --git a/javascript/raindrops/raindrops.spec.js b/javascript/raindrops/raindrops.spec.js
new file mode 100644
index 0000000..7d16076
--- /dev/null
+++ b/javascript/raindrops/raindrops.spec.js
@@ -0,0 +1,52 @@
+import { convert } from './raindrops';
+
+describe('Raindrops', () => {
+  test('the sound for 1 is 1', () => expect(convert(1)).toEqual('1'));
+
+  test('the sound for 3 is Pling', () => expect(convert(3)).toEqual('Pling'));
+
+  test('the sound for 5 is Plang', () => expect(convert(5)).toEqual('Plang'));
+
+  test('the sound for 7 is Plong', () => expect(convert(7)).toEqual('Plong'));
+
+  test('the sound for 6 is Pling as it has a factor 3', () =>
+    expect(convert(6)).toEqual('Pling'));
+
+  test('2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base', () =>
+    expect(convert(8)).toEqual('8'));
+
+  test('the sound for 9 is Pling as it has a factor 3', () =>
+    expect(convert(9)).toEqual('Pling'));
+
+  test('the sound for 10 is Plang as it has a factor 5', () =>
+    expect(convert(10)).toEqual('Plang'));
+
+  test('the sound for 14 is Plong as it has a factor of 7', () =>
+    expect(convert(14)).toEqual('Plong'));
+
+  test('the sound for 15 is PlingPlang as it has factors 3 and 5', () =>
+    expect(convert(15)).toEqual('PlingPlang'));
+
+  test('the sound for 21 is PlingPlong as it has factors 3 and 7', () =>
+    expect(convert(21)).toEqual('PlingPlong'));
+
+  test('the sound for 25 is Plang as it has a factor 5', () =>
+    expect(convert(25)).toEqual('Plang'));
+
+  test('the sound for 27 is Pling as it has a factor 3', () =>
+    expect(convert(27)).toEqual('Pling'));
+
+  test('the sound for 35 is PlangPlong as it has factors 5 and 7', () =>
+    expect(convert(35)).toEqual('PlangPlong'));
+
+  test('the sound for 49 is Plong as it has a factor 7', () =>
+    expect(convert(49)).toEqual('Plong'));
+
+  test('the sound for 52 is 52', () => expect(convert(52)).toEqual('52'));
+
+  test('the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7', () =>
+    expect(convert(105)).toEqual('PlingPlangPlong'));
+
+  test('the sound for 3125 is Plang as it has a factor 5', () =>
+    expect(convert(3125)).toEqual('Plang'));
+});
k/mu/blame/032array.cc?h=main&id=758e0fc666cc62f611bb0186ed230df51db57c63'>^
49659e72 ^
a55bbd06 ^
f4647409 ^
1fb0cf9e ^
f4647409 ^

93d4cc93 ^

f4647409 ^
93d4cc93 ^
f4647409 ^




b8348923 ^

1211a3ab ^
1fb0cf9e ^
b8348923 ^
758e0fc6 ^
c36eb25c ^


4a943d4e ^








c36eb25c ^
f7c58ffd ^




4a943d4e ^











c36eb25c ^
f7c58ffd ^











93d4cc93 ^
f7c58ffd ^



758e0fc6 ^

8dccf184 ^

1211a3ab ^
8dccf184 ^




4a943d4e ^



























1e76d01d ^
7284d503 ^

4a943d4e ^
















































07d35c4a ^
1848b18f ^

a55bbd06 ^
795f5244 ^
b8515e8a ^
a55bbd06 ^
b8515e8a ^
2b250717 ^
e4630643 ^

3473c63a ^
15936c91 ^
1ad3fe9e ^
9dcbec39 ^
18e626df ^

3473c63a ^
15936c91 ^

9dcbec39 ^
15936c91 ^

fb85b3b4 ^
3473c63a ^
15936c91 ^
090cad5c ^
bb7142db ^
9dcbec39 ^
fb85b3b4 ^

b8515e8a ^



3473c63a ^
15936c91 ^
b24eb476 ^
c442a5ad ^
18e626df ^
2b250717 ^
46026f62 ^

3473c63a ^
15936c91 ^

15936c91 ^
2b250717 ^
551d155c ^

090cad5c ^
9f7f62ed ^
c442a5ad ^

fb1fcbc9 ^

a55bbd06 ^


7e9c6925 ^
3377364a ^
9f7f62ed ^



3377364a ^
93d4cc93 ^








9f7f62ed ^
93d4cc93 ^
9f7f62ed ^
7e9c6925 ^

b8348923 ^
34068eb3 ^
93d4cc93 ^


91ec4681 ^
93d4cc93 ^
b8348923 ^
93d4cc93 ^
b8348923 ^


34068eb3 ^
91ec4681 ^




23d3a022 ^
91ec4681 ^



93d4cc93 ^




4a943d4e ^





















































fb85b3b4 ^
5c6840b8 ^

4a943d4e ^








5c6840b8 ^
991d76f3 ^
1848b18f ^
4a943d4e ^










1848b18f ^

991d76f3 ^
a55bbd06 ^
991d76f3 ^
b8515e8a ^
991d76f3 ^

2b250717 ^
e4630643 ^

3473c63a ^
15936c91 ^
1ad3fe9e ^
9dcbec39 ^
46026f62 ^

3473c63a ^
15936c91 ^

9dcbec39 ^
991d76f3 ^

3473c63a ^
15936c91 ^
090cad5c ^
991d76f3 ^
9dcbec39 ^
fb85b3b4 ^

fc19980d ^

0d219477 ^


fc19980d ^
b8515e8a ^


991d76f3 ^
3473c63a ^
15936c91 ^
b24eb476 ^
18e626df ^
2b250717 ^
18e626df ^

3473c63a ^
15936c91 ^

15936c91 ^
2b250717 ^
551d155c ^

9f7f62ed ^
c442a5ad ^
991d76f3 ^

59874868 ^
991d76f3 ^
6e793202 ^
6c96a437 ^
c442a5ad ^
991d76f3 ^

59874868 ^
a55bbd06 ^
c8a58cdc ^
4a943d4e ^








































0d219477 ^
c8a58cdc ^

4a943d4e ^










c8a58cdc ^



795f5244 ^
b8515e8a ^
c8a58cdc ^
b8515e8a ^
2b250717 ^
e4630643 ^

3473c63a ^
15936c91 ^

9dcbec39 ^
c8a58cdc ^

b8515e8a ^



3473c63a ^
15936c91 ^

2b250717 ^
18e626df ^

cfb142b9 ^
15936c91 ^
c8a58cdc ^

e74a2940 ^




991d76f3 ^
e74a2940 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635