forked from trekhleb/javascript-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit cf61af5
optimized for loop & corrected comments (trekhleb#617)
The existing insertion sort implementation began by iterating from
0 until the end of the array, but it is only necessary to
iterate from 1 until the end of the array, since at the
0th index, there is nothing to compare to the left of
the element.
In order to complete this change, I also had to update the tests
to reflect the fact that the algorithm visits each index 1 less
time.
Finally, I corrected the grammar/wording of the comments.
Co-authored-by: Oleksii Trekhleb <trehleb@gmail.com>1 parent 8124034 commit cf61af5
File tree
2 files changed
+7
-7
lines changed- src/algorithms/sorting/insertion-sort
- __test__
2 files changed
+7
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | - | ||
8 | + | ||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | - | ||
15 | - | ||
14 | + | ||
15 | + | ||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | - | ||
12 | - | ||
13 | - | ||
14 | - | ||
11 | + | ||
12 | + | ||
13 | + | ||
14 | + | ||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
0 commit comments