Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Resolved Issue #3972 #4784

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
open System

let alternatingCase (input: string) =
let convert (c: char) (isUpper: bool) =
match Char.IsLetter c with
| true -> if isUpper then Char.ToUpper c else Char.ToLower c
| false -> c

let rec loop (str: string) (index: int) (isUpper: bool) =
if index < str.Length then
let updatedChar = convert str.[index] isUpper
let nextIsUpper = if Char.IsLetter str.[index] then not isUpper else isUpper
updatedChar.ToString() + loop str (index + 1) nextIsUpper
else
""

loop input 0 false // Start with lowercase for the first character

// Example usage
let result = alternatingCase "hello world"
printfn "%s" result