I am a beginner trying to understand few coding problems to use them as base for my learning. In the snippet below there are two functions at a time. How will the implementation and the sequence for the dart code snippet below be?
List<int> forAll(Function f, List<int> intList){
var newList = List<int>();
for(var i = 0; i < intList.length; i ++){
newList.add(f(intList[i]));
}
return newList;
}
// Recursive factorial function
int factorial(int x) {
if (x == 1) {
return 1;
} else {
return x*factorial(x-1);
}
}
main() {
var tester = [1,2,3];
var result = forAll(factorial, tester);
print(tester);
print(result);
}
Output
[1, 2, 3]
[1, 2, 6]