feat: add List.map method with test for element transformation

Implement a `map` method on the List class that applies a given function `f` to each element, returning a new list with the transformed values. Includes a test case verifying incrementing each element by 1.
This commit is contained in:
Kyle Marek-Spartz
2014-02-15 05:06:29 +00:00
parent 5f505c2a02
commit 48ef257973
3 changed files with 21 additions and 0 deletions
+8
View File
@@ -59,6 +59,14 @@ static const char* libSource =
" }\n"
" return result\n"
" }\n"
" \n"
" map (f) {\n"
" var result = []\n"
" for (element in this) {\n"
" result.add(f.call(element))\n"
" }\n"
" return result\n"
" }\n"
"}\n";
// Validates that the given argument in [args] is a Num. Returns true if it is.