-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial files for raindrops approaches
- Loading branch information
Showing
6 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"approaches": [ | ||
{ | ||
"uuid": "8338d92d-8719-4c1b-aabe-95821881c4cd", | ||
"slug": "if-else-statements", | ||
"title": "If Else Statements", | ||
"blurb": "Use conditional logic to test each factor rule", | ||
"authors": [ | ||
"BNAndras" | ||
] | ||
}, | ||
{ | ||
"uuid": "c214970f-ff2b-43a2-93a6-6478c8ec1c63", | ||
"slug": "list-of-rules", | ||
"title": "Looping Over List of Rules", | ||
"blurb": "Loop over a list of factor rules and apply them", | ||
"authors": [ | ||
"BNAndras" | ||
] | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
exercises/practice/raindrops/.approaches/if-else-statements/content.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# If Else Statements | ||
|
||
```vim | ||
function! Raindrops(number) abort | ||
let l:str = '' | ||
if a:number % 3 == 0 | ||
let l:str .= 'Pling' | ||
endif | ||
if a:number % 5 == 0 | ||
let l:str .= 'Plang' | ||
endif | ||
if a:number % 7 == 0 | ||
let l:str .= 'Plong' | ||
endif | ||
return empty(l:str) ? string(a:number) : l:str | ||
endfunction | ||
``` |
8 changes: 8 additions & 0 deletions
8
exercises/practice/raindrops/.approaches/if-else-statements/snippet.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function! Raindrops(number) abort | ||
let l:str = '' | ||
if a:number % 3 == 0 | ||
let l:str .= 'Pling' | ||
endif | ||
if a:number % 5 == 0 | ||
let l:str .= 'Plang' | ||
# cut for snippet brevity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Introduction | ||
|
||
Here are two common approaches for this exercise. | ||
|
||
## Approach: If else statements | ||
|
||
```vim | ||
function! Raindrops(number) abort | ||
let l:str = '' | ||
if a:number % 3 == 0 | ||
let l:str .= 'Pling' | ||
endif | ||
if a:number % 5 == 0 | ||
let l:str .= 'Plang' | ||
endif | ||
if a:number % 7 == 0 | ||
let l:str .= 'Plong' | ||
endif | ||
return empty(l:str) ? string(a:number) : l:str | ||
endfunction | ||
``` | ||
|
||
For more information, check the [if else statements approach][approach-if-else-statements]. | ||
|
||
## Approach: Looping over a list of rules | ||
|
||
```vim | ||
let s:rules = [[3, 'Pling'], [5, 'Plang'], [7, 'Plong']] | ||
function! Raindrops(number) abort | ||
let l:str = '' | ||
for [l:factor, l:sound] in s:rules | ||
if a:number % l:factor == 0 | ||
let l:str .= l:sound | ||
endif | ||
endfor | ||
return empty(l:str) ? string(a:number) : l:str | ||
endfunction | ||
``` | ||
|
||
For more information, check the [looping over a list of rules approach][approach-list-of-rules]. | ||
|
||
|
||
[approach-if-else-statements]: https://exercism.org/tracks/vimscript/exercises/raindrops/approaches/if-else-statements | ||
[approach-boolean-chain]: https://exercism.org/tracks/vimscript/exercises/raindrops/approaches/list-of-rules |
17 changes: 17 additions & 0 deletions
17
exercises/practice/raindrops/.approaches/list-of-rules/content.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Looping Over A List of Rules | ||
|
||
```vim | ||
let s:rules = [[3, 'Pling'], [5, 'Plang'], [7, 'Plong']] | ||
function! Raindrops(number) abort | ||
let l:str = '' | ||
for [l:factor, l:sound] in s:rules | ||
if a:number % l:factor == 0 | ||
let l:str .= l:sound | ||
endif | ||
endfor | ||
return empty(l:str) ? string(a:number) : l:str | ||
endfunction | ||
``` |
8 changes: 8 additions & 0 deletions
8
exercises/practice/raindrops/.approaches/list-of-rules/snippet.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let s:rules = [[3, 'Pling'], [5, 'Plang'], [7, 'Plong']] | ||
|
||
function! Raindrops(number) abort | ||
let l:str = '' | ||
for [l:factor, l:sound] in s:rules | ||
if a:number % l:factor == 0 | ||
let l:str .= l:sound | ||
# cut for snippet brevity |