Skip to content

Commit e9598e7

Browse files
committed
Initial files for raindrops approaches
1 parent 35989ee commit e9598e7

File tree

6 files changed

+120
-0
lines changed

6 files changed

+120
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"approaches": [
3+
{
4+
"uuid": "8338d92d-8719-4c1b-aabe-95821881c4cd",
5+
"slug": "if-else-statements",
6+
"title": "If Else Statements",
7+
"blurb": "Use conditional logic to test each factor rule",
8+
"authors": [
9+
"BNAndras"
10+
]
11+
},
12+
{
13+
"uuid": "c214970f-ff2b-43a2-93a6-6478c8ec1c63",
14+
"slug": "list-of-rules",
15+
"title": "Looping Over List of Rules",
16+
"blurb": "Loop over a list of factor rules and apply them",
17+
"authors": [
18+
"BNAndras"
19+
]
20+
}
21+
]
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# If Else Statements
2+
3+
```vim
4+
function! Raindrops(number) abort
5+
let l:str = ''
6+
if a:number % 3 == 0
7+
let l:str .= 'Pling'
8+
endif
9+
if a:number % 5 == 0
10+
let l:str .= 'Plang'
11+
endif
12+
if a:number % 7 == 0
13+
let l:str .= 'Plong'
14+
endif
15+
return empty(l:str) ? string(a:number) : l:str
16+
endfunction
17+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function! Raindrops(number) abort
2+
let l:str = ''
3+
if a:number % 3 == 0
4+
let l:str .= 'Pling'
5+
endif
6+
if a:number % 5 == 0
7+
let l:str .= 'Plang'
8+
# cut for snippet brevity
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Introduction
2+
3+
Here are two common approaches for this exercise.
4+
5+
## Approach: If else statements
6+
7+
```vim
8+
function! Raindrops(number) abort
9+
let l:str = ''
10+
if a:number % 3 == 0
11+
let l:str .= 'Pling'
12+
endif
13+
if a:number % 5 == 0
14+
let l:str .= 'Plang'
15+
endif
16+
if a:number % 7 == 0
17+
let l:str .= 'Plong'
18+
endif
19+
20+
return empty(l:str) ? string(a:number) : l:str
21+
endfunction
22+
```
23+
24+
For more information, check the [if else statements approach][approach-if-else-statements].
25+
26+
## Approach: Looping over a list of rules
27+
28+
```vim
29+
let s:rules = [[3, 'Pling'], [5, 'Plang'], [7, 'Plong']]
30+
31+
function! Raindrops(number) abort
32+
let l:str = ''
33+
34+
for [l:factor, l:sound] in s:rules
35+
if a:number % l:factor == 0
36+
let l:str .= l:sound
37+
endif
38+
endfor
39+
40+
return empty(l:str) ? string(a:number) : l:str
41+
endfunction
42+
```
43+
44+
For more information, check the [looping over a list of rules approach][approach-list-of-rules].
45+
46+
47+
[approach-if-else-statements]: https://exercism.org/tracks/vimscript/exercises/raindrops/approaches/if-else-statements
48+
[approach-boolean-chain]: https://exercism.org/tracks/vimscript/exercises/raindrops/approaches/list-of-rules
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Looping Over A List of Rules
2+
3+
```vim
4+
let s:rules = [[3, 'Pling'], [5, 'Plang'], [7, 'Plong']]
5+
6+
function! Raindrops(number) abort
7+
let l:str = ''
8+
9+
for [l:factor, l:sound] in s:rules
10+
if a:number % l:factor == 0
11+
let l:str .= l:sound
12+
endif
13+
endfor
14+
15+
return empty(l:str) ? string(a:number) : l:str
16+
endfunction
17+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
let s:rules = [[3, 'Pling'], [5, 'Plang'], [7, 'Plong']]
2+
3+
function! Raindrops(number) abort
4+
let l:str = ''
5+
for [l:factor, l:sound] in s:rules
6+
if a:number % l:factor == 0
7+
let l:str .= l:sound
8+
# cut for snippet brevity

0 commit comments

Comments
 (0)