made with esnextbin
Last active
March 16, 2016 18:11
-
-
Save Nitive/aca08fb4dc66a8b4587c to your computer and use it in GitHub Desktop.
esnextbin sketch
This file contains 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 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
import { compact, uniq, take } from 'lodash' | |
const wrap = function (fn, ...args) { | |
return fn(this, ...args) | |
} | |
const exampleData = [ | |
{ date: '03/12/2012', text: '12 марта' }, | |
{ date: '03/13/2012', text: '13 марта' }, | |
{ date: '04/12/1961', text: '12 апреля' }, | |
null, | |
{ date: '06/22/2014', text: '12 июля' }, | |
] | |
const getDateProp = obj => obj.date | |
const getYear = dateString => (new Date(dateString)).getFullYear() | |
const result = exampleData | |
::wrap(compact) | |
.map(getDateProp) | |
.map(getYear) | |
::wrap(uniq) | |
.sort() | |
::wrap(take, 2) | |
console.log(result) // [1961, 2012] |
This file contains 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": { | |
"lodash": "4.5.0" | |
} | |
} |
This file contains 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 _context; | |
var _lodash = require('lodash'); | |
var wrap = function wrap(fn) { | |
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | |
args[_key - 1] = arguments[_key]; | |
} | |
return fn.apply(undefined, [this].concat(args)); | |
}; | |
var exampleData = [{ date: '03/12/2012', text: '12 марта' }, { date: '03/13/2012', text: '13 марта' }, { date: '04/12/1961', text: '12 апреля' }, null, { date: '06/22/2014', text: '12 июля' }]; | |
var getDateProp = function getDateProp(obj) { | |
return obj.date; | |
}; | |
var getYear = function getYear(dateString) { | |
return new Date(dateString).getFullYear(); | |
}; | |
var result = (_context = (_context = wrap.call(exampleData, _lodash.compact).map(getDateProp).map(getYear), wrap).call(_context, _lodash.uniq).sort(), wrap).call(_context, _lodash.take, 2); | |
console.log(result); // [1961, 2012] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment