-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added alternating caps functionality
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @author sw5678 | ||
* @copyright Crown Copyright 2023 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
|
||
/** | ||
* Alternating caps operation | ||
*/ | ||
class AlternatingCaps extends Operation { | ||
|
||
/** | ||
* AlternatingCaps constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "Alternating Caps"; | ||
this.module = "Default"; | ||
this.description = "Alternating caps, also known as studly caps, sticky caps, or spongecase is a form of text notation in which the capitalization of letters varies by some pattern, or arbitrarily. An example of this would be spelling 'alternative caps' as 'aLtErNaTiNg CaPs'."; | ||
this.infoURL = "https://en.wikipedia.org/wiki/Alternating_caps"; | ||
this.inputType = "string"; | ||
this.outputType = "string"; | ||
this.args= []; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
run(input, args) { | ||
let output = ""; | ||
for (let i = 0; i < input.length; i++) { | ||
if (i % 2 === 0) { | ||
output += input[i].toLowerCase(); | ||
} else { | ||
output += input[i].toUpperCase(); | ||
} | ||
} | ||
return output; | ||
} | ||
} | ||
|
||
export default AlternatingCaps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* @author sw5678 | ||
* @copyright Crown Copyright 2024 | ||
* @license Apache-2.0 | ||
*/ | ||
import TestRegister from "../../lib/TestRegister.mjs"; | ||
|
||
TestRegister.addTests([ | ||
{ | ||
"name": "AlternatingCaps: Basic Example", | ||
"input": "Hello, world!", | ||
"expectedOutput": "hElLo, WoRlD!", | ||
"recipeConfig": [ | ||
{ | ||
"op": "Alternating Caps", | ||
"args": [] | ||
}, | ||
], | ||
} | ||
]); |