Skip to content

Commit

Permalink
Initial files for raindrops approaches
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras committed Jan 22, 2024
1 parent 35989ee commit e9598e7
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
22 changes: 22 additions & 0 deletions exercises/practice/raindrops/.approaches/config.json
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"
]
}
]
}
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
```
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
48 changes: 48 additions & 0 deletions exercises/practice/raindrops/.approaches/introduction.md
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 exercises/practice/raindrops/.approaches/list-of-rules/content.md
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
```
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

0 comments on commit e9598e7

Please sign in to comment.