forked fromtrekhleb/javascript-algorithms
- Notifications
You must be signed in to change notification settings - Fork0
Commitcf61af5
optimized for loop & corrected comments (trekhleb#617)
The existing insertion sort implementation began by iterating from0 until the end of the array, but it is only necessary toiterate from 1 until the end of the array, since at the0th index, there is nothing to compare to the left ofthe element.In order to complete this change, I also had to update the teststo reflect the fact that the algorithm visits each index 1 lesstime.Finally, I corrected the grammar/wording of the comments.Co-authored-by: Oleksii Trekhleb <trehleb@gmail.com>1 parent8124034 commitcf61af5
File tree
2 files changed
+7
-7
lines changed- src/algorithms/sorting/insertion-sort
- __test__
2 files changed
+7
-7
lines changedLines changed: 3 additions & 3 deletions
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
Comments
(0)