{"size": 614, "ext": "js", "max_stars_repo_path": "lang/JavaScript/GnomeSort.js", "max_stars_repo_name": "ethansaxenian/RosettaDecode", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lang/JavaScript/GnomeSort.js", "max_issues_repo_name": "ethansaxenian/RosettaDecode", "max_issues_repo_issues_event_min_datetime": "2021-05-02T10:59:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-14T10:02:22.000Z", "max_forks_repo_path": "lang/JavaScript/GnomeSort.js", "max_forks_repo_name": "ethansaxenian/RosettaDecode", "max_forks_repo_forks_event_min_datetime": "2021-11-26T20:43:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T20:43:19.000Z"}
{"max_stars_count": null, "max_issues_count": 25, "max_forks_count": 1, "avg_line_length": 19.1875, "max_line_length": 112, "alphanum_fraction": 0.5895765472}
/*
 * Gnome sort is a sort algorithm that moving an element to its proper place is accomplished by a series of swap
 * more information: https://en.wikipedia.org/wiki/Gnome_sort
 *
 */
function gnomeSort (items) {
  if (items.length <= 1) {
    return
  }

  let i = 1

  while (i < items.length) {
    if (items[i - 1] <= items[i]) {
      i++
    } else {
      [items[i], items[i - 1]] = [items[i - 1], items[i]]

      i = Math.max(1, i - 1)
    }
  }
}

// Implementation of gnomeSort

var ar = [5, 6, 7, 8, 1, 2, 12, 14]
// Array before Sort
console.log(ar)
gnomeSort(ar)
// Array after sort
console.log(ar)
