Created
November 27, 2011 10:07
-
-
Save devnoo/1397339 to your computer and use it in GitHub Desktop.
Seven languages in seven weeks : Solutions IO Day2 sum multidimensional
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List deepSum := method( | |
total := 0 | |
self foreach(i, element, (if (element type == "List", total = total + element deepSum , total = total + element))) | |
total | |
) | |
array := list(list(1,2), list(3,4), 5) | |
array deepSum println | |
array2 := list(list(1,list(2,3)), list(3,4), 5) | |
array2 deepSum println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment