<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
/*
* Natural Sort algorithm for Javascript
*
* Author: Lauri Rooden
*
* code source on https://github.com/litejs/natural-compare-lite
*
*/
var naturalSort = function(a, b) {
if (a != b) for (var i, ca, cb = 1, ia = 0, ib = 0; cb;) {
ca = a.charCodeAt(ia++) || 0;
cb = b.charCodeAt(ib++) || 0;
if (ca < 58 && ca > 47 && cb < 58 && cb > 47) {
for (i = ia; ca = a.charCodeAt(ia), ca < 58 && ca > 47; ia++);
ca = (a.slice(i - 1, ia) | 0) + 1;
for (i = ib; cb = b.charCodeAt(ib), cb < 58 && cb > 47; ib++);
cb = (b.slice(i - 1, ib) | 0) + 1;
}
if (ca != cb) return (ca < cb) ? -1 : 1;
}
return 0;
};
/*
* Sample usages, using javascript's native array's .sort() method
*
* see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
*/
var stringArray = [' ciao', 'ciao', 'hello', 'hellothere', 'hello there'];
/* non-ASCII characters, i.e. strings with accented characters (e, é, è, a, ä, etc.), */
var stringArrayWithNonAsciiChars = ['réservé', 'réserve', 'premier', 'cliché', 'communiqué', 'café', 'adieu'];
var numericStringArray = ['80', '9', '700'];
var stringAlphanumericalOne = [' ','9','1','ä','z','-','a','é',';'];
var stringAlphanumericalTwo = ['img ','img9','imga','img-' , 'imgz', 'imgä','img1', 'imgé','img;'];
var stringAlphanumericalThree = ['img 9','img19','imga9','img-9', 'imgz9', 'imgä9', 'imgé9','img;9','img99'];
console.log( stringArray.sort(naturalSort) );
console.log( stringArrayWithNonAsciiChars.sort(naturalSort));
console.log( numericStringArray.sort(naturalSort) );
console.log( stringAlphanumericalOne.sort(naturalSort) );
console.log( stringAlphanumericalTwo.sort(naturalSort) );
console.log( stringAlphanumericalThree.sort(naturalSort) );
/* Basic Latin characters http://en.wikipedia.org/wiki/List_of_Unicode_characters#Basic_Latin */
var basicLatin = [' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}'];
console.log( basicLatin.sort(naturalSort) );
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |