This commit is contained in:
2025-04-03 12:31:01 +02:00
parent 868c870bf0
commit e16d4270c0
9 changed files with 61 additions and 114 deletions

View File

@@ -0,0 +1,56 @@
// Test utility functions to verify dynamic function discovery
// These functions were not in the original hardcoded lists
// Reverse a string
fn reverse_string(text) {
let result = "";
let i = text.len - 1;
// Using a different approach to reverse the string
// We'll iterate backwards with a while loop instead of using step
while i >= 0 {
result += text.substr(i, 1);
i -= 1;
}
result
}
// Count words in a string - rewritten to avoid split issues
fn count_words(text) {
if text.len == 0 {
return 0;
}
// Manual word counting implementation
let count = 1; // Start with 1 for the first word
let in_word = true;
for i in 0..text.len {
let char = text.substr(i, 1);
if char == " " {
in_word = false;
} else if !in_word {
// Found a non-space after a space = new word
count += 1;
in_word = true;
}
}
if text.substr(0, 1) == " " {
// If text starts with space, reduce count
count -= 1;
}
count
}
// Calculate factorial
fn factorial(n) {
// Ensure consistent integer type using to_int()
let num = n.to_int();
if num <= 1 {
return 1;
}
num * factorial(num-1)
}