Skip to content

Commit

Permalink
add capitalize string algorithm (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
lareii committed Jul 26, 2023
1 parent eaede39 commit d90e58b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Algorithms and data structures implemented in the Jule programming language.
- [Lower Case](./string/lower_case.jule)
- [Upper Case](./string/upper_case.jule)
- [Reverse](./string/reverse.jule)
- [Capitalize](./string/capitalize.jule)

## Contributing

Expand Down
3 changes: 3 additions & 0 deletions string/capitalize.jule
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn capitalize(mut string: str): str {
ret upper_case((str)(string[0])) + lower_case(string[1:])
}
5 changes: 5 additions & 0 deletions test.jule
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use string::{
upper_case,
lower_case,
reverse,
capitalize,
}

static mut TESTS: TestStack = TestStack.new()
Expand Down Expand Up @@ -93,6 +94,10 @@ fn add_tests_string() {
TESTS.add("reverse", fn(): bool {
ret reverse("FooBar") == "raBooF"
})

TESTS.add("capitalize", fn(): bool {
ret capitalize("foo BAR") == "Foo bar"
})
}

fn main() {
Expand Down

0 comments on commit d90e58b

Please sign in to comment.