Skip to content

Commit 02271c7

Browse files
authored
Merge pull request #83 from clovisphere/master
add Dart solution
2 parents 41b27a8 + 931f794 commit 02271c7

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

dart/for-each.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
var sections = [
3+
{
4+
'title': 'Getting Started',
5+
'resetLessonPosition': false,
6+
'lessons': [
7+
{'name': 'Welcome'},
8+
{'name': 'Installation'}
9+
]
10+
},
11+
{
12+
'title': 'Basic Operator',
13+
'resetLessonPosition': false,
14+
'lessons': [
15+
{'name': 'Addition / Substraction'},
16+
{'name': 'Multiplication / Division'}
17+
]
18+
},
19+
{
20+
'title': 'Advanced Topics',
21+
'resetLessonPosition': true,
22+
'lessons': [
23+
{'name': 'Mutability'},
24+
{'name': 'Immutability'}
25+
]
26+
}
27+
];
28+
29+
void main() {
30+
var sectionCounter = 0;
31+
var lessonCounter = 0;
32+
33+
for (var section in sections) {
34+
if (section['resetLessonPosition'] as bool) {
35+
lessonCounter = 0;
36+
}
37+
section['position'] = ++sectionCounter;
38+
39+
for (var lesson in section['lessons'] as List) {
40+
lesson['position'] = (++lessonCounter).toString();
41+
}
42+
}
43+
print(sections);
44+
}

0 commit comments

Comments
 (0)