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

Commit

Permalink
Resolved Issue #3972 (#4784)
Browse files Browse the repository at this point in the history
Co-authored-by: Vamsi Krishna Pasam <vamsikrishnapasam@Vamsis-MacBook-Pro.local>
Co-authored-by: Anandha Krishnan S <anandajith@gmail.com>
Co-authored-by: Harsh Raj <harshraj8843@gmail.com>
  • Loading branch information
4 people authored Dec 1, 2023
1 parent a30cfc3 commit d6dab5c
Showing 1 changed file with 21 additions and 0 deletions.
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

0 comments on commit d6dab5c

Please sign in to comment.