A stable array sort, because {\ttfamily Array\#sort()} is not guaranteed stable.

MIT licensed.

\href{http://travis-ci.org/Two-Screen/stable}{\texttt{ }}

\href{http://ci.testling.com/Two-Screen/stable}{\texttt{ }}\hypertarget{md_sfcode_node_modules_stable_README_autotoc_md28874}{}\doxysubsubsection{From npm}\label{md_sfcode_node_modules_stable_README_autotoc_md28874}
Install with\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install stable }

\end{DoxyCode}


Then use it in Node.\+js or some other Common\+JS environment as\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const stable = require('stable') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_stable_README_autotoc_md28875}{}\doxysubsubsection{From the browser}\label{md_sfcode_node_modules_stable_README_autotoc_md28875}
Include \href{https://raw.github.com/Two-Screen/stable/master/stable.js}{\texttt{ {\ttfamily stable.\+js}}} or the minified version \href{https://raw.github.com/Two-Screen/stable/master/stable.min.js}{\texttt{ {\ttfamily stable.\+min.\+js}}} in your page, then call {\ttfamily stable()}.\hypertarget{md_sfcode_node_modules_stable_README_autotoc_md28876}{}\doxysubsubsection{Usage}\label{md_sfcode_node_modules_stable_README_autotoc_md28876}
The default sort is, as with {\ttfamily Array\#sort}, lexicographical\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{stable(['foo', 'bar', 'baz'])  // => ['bar', 'baz', 'foo']}
\DoxyCodeLine{stable([10, 1, 5])             // => [1, 10, 5] }

\end{DoxyCode}


Unlike {\ttfamily Array\#sort}, the default sort is {\bfseries{NOT}} in-\/place. To do an in-\/place sort, use {\ttfamily stable.\+inplace}, which otherwise works the same\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const arr = [10, 1, 5]}
\DoxyCodeLine{stable(arr) === arr          // => false}
\DoxyCodeLine{stable.inplace(arr) === arr  // => true }

\end{DoxyCode}


A comparator function can be specified\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{// Regular sort() compatible comparator, that returns a number.}
\DoxyCodeLine{// This demonstrates the default behavior.}
\DoxyCodeLine{const lexCmp = (a, b) => String(a).localeCompare(b)}
\DoxyCodeLine{stable(['foo', 'bar', 'baz'], lexCmp)  // => ['bar', 'baz', 'foo']}
\DoxyCodeLine{}
\DoxyCodeLine{// Boolean comparator. Sorts `b` before `a` if true.}
\DoxyCodeLine{// This demonstrates a simple way to sort numerically.}
\DoxyCodeLine{const greaterThan = (a, b) => a > b}
\DoxyCodeLine{stable([10, 1, 5], greaterThan)  // => [1, 5, 10] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_stable_README_autotoc_md28877}{}\doxysubsubsection{License}\label{md_sfcode_node_modules_stable_README_autotoc_md28877}
Copyright (C) 2018 Angry Bytes and contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \char`\"{}\+Software\char`\"{}), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions\+:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED \char`\"{}\+AS IS\char`\"{}, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 