Miscellany
public text v1 · immutableQ: Given an array of data structures that look like:
class MenuItem {
String Name
Array<MenuItem> Children
}
write a single method that will output all the MenuItem names and include the level number in front of them:
function PrettyPrint(menuItems, level) {
foreach(MenuItem item in menuItems) {
print level + ". " + item.name
if(item.children)
PrettyPrint(item.children, level + 1)
}
}