Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: trekhleb/javascript-algorithms
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: SidKwok/javascript-algorithms
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Oct 21, 2018

  1. Copy the full SHA
    43090be View commit details
  2. InserationSort: fix lint

    SidKwok committed Oct 21, 2018
    Copy the full SHA
    f8a0ec8 View commit details
Showing with 3 additions and 4 deletions.
  1. +3 −4 src/algorithms/sorting/insertion-sort/InsertionSort.js
7 changes: 3 additions & 4 deletions src/algorithms/sorting/insertion-sort/InsertionSort.js
Original file line number Diff line number Diff line change
@@ -14,16 +14,15 @@ export default class InsertionSort extends Sort {
// Go and check if previous elements and greater then current one.
// If this is the case then swap that elements.
while (
array[currentIndex - 1] !== undefined
currentIndex - 1 >= 0
&& this.comparator.lessThan(array[currentIndex], array[currentIndex - 1])
) {
// Call visiting callback.
this.callbacks.visitingCallback(array[currentIndex - 1]);

// Swap the elements.
const tmp = array[currentIndex - 1];
array[currentIndex - 1] = array[currentIndex];
array[currentIndex] = tmp;
[array[currentIndex - 1], array[currentIndex]] = [
array[currentIndex], array[currentIndex - 1]];

// Shift current index left.
currentIndex -= 1;