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 +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import searchAndReplace from './search-and-replace'
28
28
import sqrt from './sqrt'
29
29
import toPower from './to-power'
30
30
import mod from './mod'
31
+ import swapCase from './swap-case'
31
32
32
33
export {
33
34
initArray ,
@@ -59,4 +60,5 @@ export {
59
60
sqrt ,
60
61
toPower ,
61
62
mod ,
63
+ swapCase ,
62
64
}
Original file line number Diff line number Diff line change
1
+ export default swapCase
2
+
3
+ /**
4
+ * Original source: http://stackoverflow.com/a/40192407/4204587
5
+ *
6
+ * This method will swap cases for a given string.
7
+ *
8
+ * @param {String } s - string for case swapping
9
+ * @return {String } - string with all cases swapped
10
+ */
11
+ function swapCase ( s ) {
12
+ return s . split ( '' ) . map ( function swapper ( c ) {
13
+ return c === c . toUpperCase ( ) ?
14
+ c . toLowerCase ( ) :
15
+ c . toUpperCase ( )
16
+ } ) . join ( '' )
17
+ }
Original file line number Diff line number Diff line change
1
+ import test from 'ava'
2
+ import { swapCase } from '../src'
3
+
4
+ test ( 'Swap cases from string ' , t => {
5
+ const original = 'That\'s one small step for a DEVELOPER, one giant leap for a Community.'
6
+ const expected = 'tHAT\'S ONE SMALL STEP FOR A developer, ONE GIANT LEAP FOR A cOMMUNITY.'
7
+ const actual = swapCase ( original )
8
+ t . is ( actual , expected )
9
+ } )
You can’t perform that action at this time.
0 commit comments