Skip to content

Instantly share code, notes, and snippets.

@aledoroshenko
Last active October 25, 2016 19:35
Show Gist options
  • Save aledoroshenko/1fbb477201f67a68d1bac5ad20625383 to your computer and use it in GitHub Desktop.
Save aledoroshenko/1fbb477201f67a68d1bac5ad20625383 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!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 -->
</body>
</html>
import expect from 'expect';
import _ from 'lodash';
var items = [
{name: 'ownedFolder1', isFolder: true, isShareOwner: true},
{name: 'ownedFolder2', isFolder: true, isShareOwner: true},
{name: 'notOwnedFolder', isFolder: true, isShareOwner: false},
{name: 'ownedFile', isFolder: false, isShareOwner: true},
{name: 'notOwnedFile', isFolder: false, isShareOwner: false}
]
_.mixin({ 'isFolder': isFolder, 'isShareOwner': isShareOwner, 'validateEvery': _.curry(validateEvery, 2) });
var getOwnedFolders = function(items) {
return _.filter(items, _.validateEvery(_.isFolder, _.isShareOwner));
};
console.table(getOwnedFolders(items))
expect(getOwnedFolders(items)).toEqual([items[0], items[1]]);
console.log('Tests passed');
// Lib functions below
function validateEvery() {
var validators = _.map(arguments);
return function(items) {
return _.every(_.map(_.castArray(items), function(item) {
return _.overEvery(validators)(item);
}));
};
}
function isFolder(item) {return item.isFolder};
function isShareOwner(item) {return item.isShareOwner};
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"expect": "1.20.2",
"lodash": "4.16.4"
}
}
'use strict';
var _expect = require('expect');
var _expect2 = _interopRequireDefault(_expect);
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var items = [{ name: 'ownedFolder1', isFolder: true, isShareOwner: true }, { name: 'ownedFolder2', isFolder: true, isShareOwner: true }, { name: 'notOwnedFolder', isFolder: true, isShareOwner: false }, { name: 'ownedFile', isFolder: false, isShareOwner: true }, { name: 'notOwnedFile', isFolder: false, isShareOwner: false }];
_lodash2.default.mixin({ 'isFolder': isFolder, 'isShareOwner': isShareOwner, 'validateEvery': _lodash2.default.curry(validateEvery, 2) });
var getOwnedFolders = function getOwnedFolders(items) {
return _lodash2.default.filter(items, _lodash2.default.validateEvery(_lodash2.default.isFolder, _lodash2.default.isShareOwner));
};
console.table(getOwnedFolders(items));
(0, _expect2.default)(getOwnedFolders(items)).toEqual([items[0], items[1]]);
console.log('Tests passed');
// Lib functions below
function validateEvery() {
var validators = _lodash2.default.map(arguments);
return function (items) {
return _lodash2.default.every(_lodash2.default.map(_lodash2.default.castArray(items), function (item) {
return _lodash2.default.overEvery(validators)(item);
}));
};
}
function isFolder(item) {
return item.isFolder;
};
function isShareOwner(item) {
return item.isShareOwner;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment