diff --git a/exercises/practice/reverse-string/.approaches/config.json b/exercises/practice/reverse-string/.approaches/config.json new file mode 100644 index 0000000..08a22d1 --- /dev/null +++ b/exercises/practice/reverse-string/.approaches/config.json @@ -0,0 +1,22 @@ +{ + "approaches": [ + { + "uuid": "b7d9f537-d0f7-4f80-b22a-c74ad88b949f", + "slug": "list-of-characters", + "title": "Reverse a List of Characters", + "blurb": "Explode the string into a list of characters and reverse the list", + "authors": [ + "BNAndras" + ] + }, + { + "uuid": "8a1adc50-f84f-4d3d-acdb-26c1677d4c69", + "slug": "looping-in-reverse", + "title": "Looping in Reverse", + "blurb": "Loop over the string backwards and build up a new string", + "authors": [ + "BNAndras" + ] + } + ] +} diff --git a/exercises/practice/reverse-string/.approaches/introduction.md b/exercises/practice/reverse-string/.approaches/introduction.md new file mode 100644 index 0000000..1a8d31e --- /dev/null +++ b/exercises/practice/reverse-string/.approaches/introduction.md @@ -0,0 +1,31 @@ +# Introduction + +There are two common approaches highlighted here for this exercise. + +## Approach: Reversing a list of characters + +```vim +function! Reverse(text) abort + return join(reverse(split(a:text, '\zs')), '') +endfunction +``` + +For more information, check the [reversing a list of characters approach][approach-list-of-characters]. + +## Approach: Looping in reverse + +```vim +function! Reverse(text) abort + let l:reversed = "" + for i in range(len(a:text) - 1, -1, -1) + let l:reversed .= a:text[i] + endfor + return reversed +endfunction +``` + +For more information, check the [looping in reverse approach][approach-loop-in-reverse]. + +[modulo-operator]: https://en.wikipedia.org/wiki/Modulo +[approach-list-of-characters]: https://exercism.org/tracks/vimscript/exercises/reverse-string/approaches/list-of-characters +[approach-looping-in-reverse]: https://exercism.org/tracks/vimscript/exercises/reverse-string/approaches/looping-in-reverse diff --git a/exercises/practice/reverse-string/.approaches/list-of-characters/content.md b/exercises/practice/reverse-string/.approaches/list-of-characters/content.md new file mode 100644 index 0000000..3954246 --- /dev/null +++ b/exercises/practice/reverse-string/.approaches/list-of-characters/content.md @@ -0,0 +1,7 @@ +# Reverse a List of Characters + +```vim +function! Reverse(text) abort + return join(reverse(split(a:text, '\zs')), '') +endfunction +``` diff --git a/exercises/practice/reverse-string/.approaches/list-of-characters/snippet.txt b/exercises/practice/reverse-string/.approaches/list-of-characters/snippet.txt new file mode 100644 index 0000000..78d2da8 --- /dev/null +++ b/exercises/practice/reverse-string/.approaches/list-of-characters/snippet.txt @@ -0,0 +1,3 @@ +function! Reverse(text) abort + return join(reverse(split(a:text, '\zs')), '') +endfunction \ No newline at end of file diff --git a/exercises/practice/reverse-string/.approaches/looping-in-reverse/content.md b/exercises/practice/reverse-string/.approaches/looping-in-reverse/content.md new file mode 100644 index 0000000..9a279dd --- /dev/null +++ b/exercises/practice/reverse-string/.approaches/looping-in-reverse/content.md @@ -0,0 +1,11 @@ +# Loop In Reverse + +```vim +function! Reverse(text) abort + let l:reversed = "" + for i in range(len(a:text) - 1, -1, -1) + let l:reversed .= a:text[i] + endfor + return reversed +endfunction +``` diff --git a/exercises/practice/reverse-string/.approaches/looping-in-reverse/snippet.txt b/exercises/practice/reverse-string/.approaches/looping-in-reverse/snippet.txt new file mode 100644 index 0000000..a695356 --- /dev/null +++ b/exercises/practice/reverse-string/.approaches/looping-in-reverse/snippet.txt @@ -0,0 +1,7 @@ +function! Reverse(text) abort + let l:reversed = "" + for i in range(len(a:text) - 1, -1, -1) + let l:reversed .= a:text[i] + endfor + return reversed +endfunction \ No newline at end of file