diff --git a/README.md b/README.md index 1b3a383..bcc622f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # javascript-references -Material to reference when working with JavaScript + +Material to reference when working with JavaScript diff --git a/quicksort/README.md b/quicksort/README.md new file mode 100644 index 0000000..d7f1081 --- /dev/null +++ b/quicksort/README.md @@ -0,0 +1,3 @@ +### Quicksort in JavaScript + +An efficient sorting algorithm, serving as a systematic method for placing the elements of a random access file or an array in order. See https://en.wikipedia.org/wiki/Quicksort diff --git a/quicksort/index.js b/quicksort/index.js new file mode 100644 index 0000000..3924d6b --- /dev/null +++ b/quicksort/index.js @@ -0,0 +1,35 @@ +/** + * This is an implementation of the Quicksort algorithm written in JavaScript. + * See https://en.wikipedia.org/wiki/Quicksort#Algorithm + */ + +/** + * The following code contains syntax that, if written incorrectly, would be caught by strict mode. + * See https://github.com/floatsoft/javascript-references/blob/hello-world/varDeclaration.js#L1-L7 + */ +"use strict"; + +/** + * We declare a function named quicksort with a single parameter; arr. + * See https://github.com/floatsoft/javascript-references/blob/bubble-sort/bubble-sort/index.js#L13-L19 + */ +function quicksort(arr) { + /** + * We return our sorted array, arr. + * See https://github.com/floatsoft/javascript-references/blob/bubble-sort/bubble-sort/index.js#L171-L176 + */ + return arr; +} + +/** + * We declare an array of unsorted numbers using the array literal method, + * we name our new variable unsortedNumbersList. + * See https://github.com/floatsoft/javascript-references/blob/bubble-sort/bubble-sort/index.js#L179-L193 + */ +var unsortedNumbersList = [8, 5, 6, 9, 3, 1, 4, 2, 7, 10]; + +/** + * We call our quicksort function, passing our unsortedNumbersList as a single argument. + * See https://github.com/floatsoft/javascript-references/blob/bubble-sort/bubble-sort/index.js#L195-L201 + */ +quicksort(unsortedNumbersList);