Skip to content

Commit 00adc99

Browse files
authored
Merge pull request #76 from mamantoha/fix-crystal-with-map
fix Crystal with map implementation
2 parents 334cbc8 + f5906ca commit 00adc99

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

crystal/with_map.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ def indexing_lessons(lessons : Array)
3131
lessons.map_with_index(1) { |lesson, index| lesson.merge({ position: index}) }
3232
end
3333

34-
selected_lessons = sections.map { |section| section[:lessons] }.flatten
34+
selected_lessons = sections.flat_map(&.[:lessons])
3535
indexed_lessons = indexing_lessons(selected_lessons)
3636

37-
formated_section = sections.map do |section|
37+
formated_section = sections.map_with_index(1) do |section, i|
3838
formated_lessons = indexed_lessons.shift(section[:lessons].size)
3939
if section[:reset_lesson_position]
4040
formated_lessons = indexing_lessons(section[:lessons])
4141
end
42-
section.merge(lessons: formated_lessons)
42+
section.merge(position: i, lessons: formated_lessons)
4343
end
4444

45-
p formated_section
45+
pp formated_section

0 commit comments

Comments
 (0)