made with esnextbin
Created
April 22, 2017 01:47
-
-
Save dearfrankg/82c89ad0c04db17a899b4503c3842eab to your computer and use it in GitHub Desktop.
esnextbin sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>ESNextbin Sketch</title> | |
| <!-- put additional styles and scripts here --> | |
| </head> | |
| <body> | |
| <!-- put markup and other contents here --> | |
| <div id="root"></div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const collection = [ | |
| { name: 'bob', age: 20 }, | |
| { name: 'sue', age: 25 }, | |
| { name: 'Jim', age: -30 } | |
| ] | |
| const by = { | |
| nameAsc: (a, b) => { | |
| nameA = a.name.toUpperCase() | |
| nameB = b.name.toUpperCase() | |
| if (nameA < nameB) return -1 | |
| if (nameA > nameB) return 1 | |
| return 0 | |
| }, | |
| nameDesc: (a, b) => { | |
| nameA = a.name.toUpperCase() | |
| nameB = b.name.toUpperCase() | |
| if (nameA > nameB) return -1 | |
| if (nameA < nameB) return 1 | |
| return 0 | |
| } | |
| } | |
| const show = { | |
| name: c => c.name, | |
| age: c => c.age | |
| } | |
| const dump = (title, data) => { | |
| console.log(title) | |
| console.log(JSON.stringify(data)) | |
| } | |
| dump('sort by name asc', collection.sort(by.nameAsc).map(show.name)) | |
| dump('sort by name desc', collection.sort(by.nameDesc).map(show.name)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "esnextbin-sketch", | |
| "version": "0.0.0", | |
| "dependencies": { | |
| "babel-runtime": "6.22.0" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| var _stringify = require('babel-runtime/core-js/json/stringify'); | |
| var _stringify2 = _interopRequireDefault(_stringify); | |
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
| var collection = [{ name: 'bob', age: 20 }, { name: 'sue', age: 25 }, { name: 'Jim', age: -30 }]; | |
| var by = { | |
| nameAsc: function nameAsc(a, b) { | |
| nameA = a.name.toUpperCase(); | |
| nameB = b.name.toUpperCase(); | |
| if (nameA < nameB) return -1; | |
| if (nameA > nameB) return 1; | |
| return 0; | |
| }, | |
| nameDesc: function nameDesc(a, b) { | |
| nameA = a.name.toUpperCase(); | |
| nameB = b.name.toUpperCase(); | |
| if (nameA > nameB) return -1; | |
| if (nameA < nameB) return 1; | |
| return 0; | |
| } | |
| }; | |
| var show = { | |
| name: function name(c) { | |
| return c.name; | |
| }, | |
| age: function age(c) { | |
| return c.age; | |
| } | |
| }; | |
| var dump = function dump(title, data) { | |
| console.log(title); | |
| console.log((0, _stringify2.default)(data)); | |
| }; | |
| dump('sort by name asc', collection.sort(by.nameAsc).map(show.name)); | |
| dump('sort by name desc', collection.sort(by.nameDesc).map(show.name)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment