Skip to content

Instantly share code, notes, and snippets.

@myabc myabc/index.html
Created Jul 13, 2017

Embed
What would you like to do?
JS Bin // source https://jsbin.com/koqogah
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
</head>
<body>
<script id="jsbin-javascript">
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var Element = (function () {
function Element(topic, relevance, level) {
_classCallCheck(this, Element);
this.topic = topic;
this.relevance = relevance;
this.level = level;
}
_createClass(Element, [{
key: 'attr',
value: function attr(_attr) {
return this[_attr];
}
}]);
return Element;
})();
var identity = function identity(x) {
return x;
};
var getAttr = function getAttr(attr) {
var coerceFn = arguments.length <= 1 || arguments[1] === undefined ? identity : arguments[1];
return function (element) {
return coerceFn.apply(element.attr(attr));
};
};
var sorts = [getAttr('relevance'), getAttr('topic', parseInt), getAttr('level')];
var element1 = new Element('topic5', '2', 'C1');
var element2 = new Element('topic4', '1', 'J1.1.1');
var element3 = new Element('topic3', '3', '81');
var element4 = new Element('topic2', '1', 'Y1');
var element5 = new Element('topic1', '6', 'X2');
var elements = [element1, element2, element3, element4, element5];
// console.log(elements[0].attr('to'));
console.log(_.sortBy(elements, sorts));
console.log(parseInt);
</script>
<script id="jsbin-source-javascript" type="text/javascript">class Element {
constructor(topic, relevance, level) {
this.topic = topic;
this.relevance = relevance;
this.level = level;
}
attr(attr) {
return this[attr];
}
}
const identity = x => x;
const getAttr = (attr, coerceFn = identity) => element => coerceFn.apply(element.attr(attr));
let sorts = [
getAttr('relevance'),
getAttr('topic', parseInt),
getAttr('level')
];
let element1 = new Element('topic5', '2', 'C1');
let element2 = new Element('topic4', '1', 'J1.1.1');
let element3 = new Element('topic3', '3', '81');
let element4 = new Element('topic2', '1', 'Y1');
let element5 = new Element('topic1', '6', 'X2');
const elements = [
element1,
element2,
element3,
element4,
element5
];
// console.log(elements[0].attr('to'));
console.log(_.sortBy(elements, sorts));
console.log(parseInt);
</script></body>
</html>
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var Element = (function () {
function Element(topic, relevance, level) {
_classCallCheck(this, Element);
this.topic = topic;
this.relevance = relevance;
this.level = level;
}
_createClass(Element, [{
key: 'attr',
value: function attr(_attr) {
return this[_attr];
}
}]);
return Element;
})();
var identity = function identity(x) {
return x;
};
var getAttr = function getAttr(attr) {
var coerceFn = arguments.length <= 1 || arguments[1] === undefined ? identity : arguments[1];
return function (element) {
return coerceFn.apply(element.attr(attr));
};
};
var sorts = [getAttr('relevance'), getAttr('topic', parseInt), getAttr('level')];
var element1 = new Element('topic5', '2', 'C1');
var element2 = new Element('topic4', '1', 'J1.1.1');
var element3 = new Element('topic3', '3', '81');
var element4 = new Element('topic2', '1', 'Y1');
var element5 = new Element('topic1', '6', 'X2');
var elements = [element1, element2, element3, element4, element5];
// console.log(elements[0].attr('to'));
console.log(_.sortBy(elements, sorts));
console.log(parseInt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.