This repository was archived by the owner on Feb 20, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ import revstring from './revstring'
12import initArray from './init-array'
23import reduce from './reduce-to-tally'
34import flatten from './flatten'
@@ -34,6 +35,7 @@ import round from './round'
3435import checkPalindrome from './checkPalindrome'
3536
3637export {
38+ revstring ,
3739 initArray ,
3840 reduce ,
3941 flatten ,
Original file line number Diff line number Diff line change 1+ export default revstring
2+
3+ /**
4+ * Original Source: https://stackoverflow.com/a/35211814
5+ *
6+ * This method will revers the order of a the chars in a string.
7+ *
8+ * @param {String } str - string whose order to be reversed
9+ * @returns {String } - string with reversed order
10+ */
11+
12+ function revstring ( str ) {
13+ let newString = ''
14+ for ( let i = str . length ; i >= 0 ; i -- ) {
15+ newString += str . charAt ( i )
16+ }
17+ return newString
18+ }
Original file line number Diff line number Diff line change 1+ import test from 'ava'
2+ import { revstring } from '../src'
3+
4+ test ( 'string with only letters' , t => {
5+ const str = "abcdefG"
6+ const expected = "Gfedcba"
7+ const result = revstring ( str )
8+ t . is ( expected , result )
9+ } )
10+
11+ test ( 'string with letters and special characters' , t => {
12+ const str = 'abc!"§'
13+ const expected = '§"!cba'
14+ const result = revstring ( str )
15+ t . is ( expected , result )
16+ } )
You can’t perform that action at this time.
0 commit comments