diff --git a/exercises/practice/raindrops/.approaches/config.json b/exercises/practice/raindrops/.approaches/config.json new file mode 100644 index 0000000..81486c6 --- /dev/null +++ b/exercises/practice/raindrops/.approaches/config.json @@ -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" + ] + } + ] +} diff --git a/exercises/practice/raindrops/.approaches/if-else-statements/content.md b/exercises/practice/raindrops/.approaches/if-else-statements/content.md new file mode 100644 index 0000000..a029df2 --- /dev/null +++ b/exercises/practice/raindrops/.approaches/if-else-statements/content.md @@ -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 +``` diff --git a/exercises/practice/raindrops/.approaches/if-else-statements/snippet.txt b/exercises/practice/raindrops/.approaches/if-else-statements/snippet.txt new file mode 100644 index 0000000..9d19745 --- /dev/null +++ b/exercises/practice/raindrops/.approaches/if-else-statements/snippet.txt @@ -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 \ No newline at end of file diff --git a/exercises/practice/raindrops/.approaches/introduction.md b/exercises/practice/raindrops/.approaches/introduction.md new file mode 100644 index 0000000..164110c --- /dev/null +++ b/exercises/practice/raindrops/.approaches/introduction.md @@ -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 \ No newline at end of file diff --git a/exercises/practice/raindrops/.approaches/list-of-rules/content.md b/exercises/practice/raindrops/.approaches/list-of-rules/content.md new file mode 100644 index 0000000..d4f2084 --- /dev/null +++ b/exercises/practice/raindrops/.approaches/list-of-rules/content.md @@ -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 +``` diff --git a/exercises/practice/raindrops/.approaches/list-of-rules/snippet.txt b/exercises/practice/raindrops/.approaches/list-of-rules/snippet.txt new file mode 100644 index 0000000..2799d2e --- /dev/null +++ b/exercises/practice/raindrops/.approaches/list-of-rules/snippet.txt @@ -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 \ No newline at end of file