setBoard: function () { var shuffledDeck = GameHelpers.shuffle(this.deck); var selection = _.take(8, shuffledDeck); var doubled = GameHelpers.doubleArray(selection); this.gameBoard = GameHelpers.shuffle(doubled); this.emit('change'); },
const generateDigitWithMask = mask => pipe( take(length(mask)), split(''), mapIndexed((el, i) => el * mask[i]), reduce(add, 0), modulo(__, 11), subtract(11, __) )
gt.async('commits by id', function () { la(check.fn(commits.all), 'has commits.all method'); commits.all(root) .then(R.take(5)) .then(commits.byId) .then(function (result) { la(check.object(result), 'formed commits by id result', result); }) .finally(gt.start) .done(); });
it('returns an object by commit id', () => { const last5 = R.take(5) return commits .all(root) .then(last5) .then(commits.byId) .then(result => { la(is.object(result), 'result is an object') const ids = R.keys(result) ids.forEach(id => { la(is.commitId(id), 'key', id, 'should be a sha in', result) }) }) })
activitystore.pastActivitiesForGroupIds([group.id], (err3, pastActivities) => { if (err3) { return next(err3); } const registeredUserId = req && req.user ? req.user.member.id() : undefined; res.render('get', { group, users: group.members, userIsGroupMember: groupsAndMembers.memberIsInMemberList(registeredUserId, group.members), organizers: group.organizers, blogposts, blogpostsFeedUrl: req.originalUrl + '/feed', webcalURL: conf.get('publicUrlPrefix').replace('http', 'webcal') + '/activities/icalForGroup/' + group.id, upcomingGroupActivities: activities || [], recentGroupActivities: pastActivities ? R.take(5, pastActivities) : [] }); });
const transformPositions = (fullmove = 0) => pipe( mapObjIndexed((y, x) => ({ x, y })), values, sort((a, b) => b.y - a.y), drop(1), map(d => ({ fullmove: d.x.match(/.+ \d+ (\d+)/)[1], fen: d.x, x: getOpeningName(d.x), y: d.y, })), filter(d => d.fullmove > fullmove), take(10), )
Object.keys(PROPS).forEach(key => { if (this[key]) { throw new Error(`Property named '${ key }' already exists.`); } // Ensure nested property extensions are added to the hierarchy. // ie. functions as properites of parent functions, for example: // - cropMarks // - cropMarks.size const parts = key.split('.'); const ns = R.take(parts.length - 1, parts); const propName = R.takeLast(1, parts).join('.'); const parent = getPropParent(ns, this); // Store the propery. parent[propName] = (value) => this[PROP](key, value); });
var getSnippet = _.curry(function(fwdIndex, invertedIndex, words, id) { var propOfIndex = flipProp(invertedIndex); var positionsOfQuery = _.map(_.compose(_.map(parseInt), _.prop(id), propOfIndex), words); var window = minWindow(positionsOfQuery); function toPositions(pos, i) { pos--; if(pos === -1) { return positionsOfQuery[i][0]; }else{ return positionsOfQuery[i][pos]; } } var sort = _.sort((a,b) => a-b); var snippetPositions = _.compose(sort, mapIndexed(toPositions))(window); var min = _.head(snippetPositions); var max = _.last(snippetPositions); return _.take(max-min+1, _.drop(min, fwdIndex[id])); });
export default function historyReducer(state = [], action) { switch(action.type) { case MARK_FOR_HISTORY: { const { ifplId } = action; return R.pipe( R.without([ifplId]), R.concat([ifplId]), R.take(maxHistoryLen), )(state); } case INVALID_KEYS: { const { ifplId } = action; return R.reject(R.equals(ifplId), state); } } return state; }
export function getCircuitState(circuitGraph, solution, currentCalculators = {}) { if (!solution) { return {}; } const voltages = R.take(circuitGraph.numOfNodes, solution); let currents = R.drop(circuitGraph.numOfNodes, solution); const toState = model => { const state = { // currents // voltages }; const nodeIDs = model.nodes; // set voltages const vs = R.map(nodeID => voltages[nodeID], nodeIDs); state.voltages = vs; // set currents const numOfVSources = model.vSources || 0; const calculateCurrent = currentCalculators[model.id]; if (numOfVSources > 0) { // Equivalent: // const cs = R.take(numOfVSources, currents); // currents = R.drop(numOfVSources, currents); const cs = currents.splice(0, numOfVSources); state.currents = cs; } else if (calculateCurrent) { // FIXME support components with voltage sources which need // current calculating? state.currents = calculateCurrent(vs); } return state; }; return R.map(toState, circuitGraph.models); }
var inputFromCheerio = function($, options) { var meta = getCheerioMeta($, options.url); var scraped = $(options.selector); var nuggets = []; var batchUuid = uuid.v1(); var simpleSearch = simplifyText(options.search); var simpleStopTexts = simplifyText(options.filterTexts); var simpleStopWords = getStopwords( options.filterKeywords, options.filterLocale ); scraped.each(function() { var nugget = {}; var current = $(this)[0]; var prev = $(this).prev()[0]; var next = $(this).next()[0]; var text = $(this).text(); if (options.contractAdjecent) { if (next && next.name && next.name === current.name) { return; } else if (prev && prev.name && prev.name === current.name) { var siblings = $(this).prevAll(current.name); siblings.each(function() { text = $(this).text() + ' ' + text; }); } } text = sanitizeText(text); var simpleText = simplifyText(text); if (simpleText === '' || simpleText === null) { return; } if (nuggetFilter( simpleText, simpleStopTexts, simpleSearch )) { return; } nugget.source = options.url; nugget.href = getCheerioClosestHref($(this), options.url); nugget.tag = $(this)[0].name; nugget.text = text; nugget.timestamp = meta.time; nugget.uuid = uuid.v1(); nugget.batch = batchUuid; nugget.keywords = getKeywordsFromText(text, simpleStopWords); nuggets.push(nugget); }); if (options.limit) { nuggets = R.take(options.limit, nuggets); } var index = 0; nuggets = R.forEach(function(nugget) { nugget.total = nuggets.length; nugget.position = index; index++; }, nuggets); return { meta: meta, nuggets: nuggets }; };
return stopsMap.filter((routeList, stop) => { const trimmedStopId = R.take(R.length(userInput), stop) return trimmedStopId === userInput })
syntaxQuote: function (strings, ...values) { let ctx = deserializer.read(_.last(values)); let reader = new Reader(strings, ctx, _.take(values.length - 1, values)); return reader.read(); },
render: function () { var user = this.props.data; var countries = R.reverse(R.sortBy(R.prop(1), R.toPairs(user.country_list))); var changesetCount = user.changeset_count; var total = Number(user.total_road_count_add) + Number(user.total_road_count_mod) + Number(user.total_building_count_add) + Number(user.total_building_count_mod) + Number(user.total_waterway_count_add) + Number(user.total_poi_count_add); var hashtag = 'http://missingmaps.org/leaderboards/#/' + user.hashtags[hashtag]; // Round km calculation depending on length var total_buildings = Number(user.total_building_count_add)+ Number(user.total_building_count_mod); var total_road_km = Number(user.total_road_km_add).toFixed(1); total_road_km = (total_road_km.length > 4) ? Math.round(total_road_km) : total_road_km; var total_waterway_km = Number(user.total_waterway_km_add).toFixed(1); total_waterway_km = (total_waterway_km.length > 4) ? Math.round(total_waterway_km) : total_waterway_km; return ( <div id = "Stats-Container"> <div className = "Split split-contributes"> <div className = "Card-Content Split-Content"> <div className = "descriptor">Projects Contributed To</div> <table className = "table-curve"> <tbody> <tr> <th>Project Hashtag</th> <th>Changesets</th> </tr> {R.take(4, Object.keys(user.hashtags)).map(function (hashtag) { var hashtaglink = 'http://missingmaps.org/leaderboards/#/' + hashtag; return ( <tr key={hashtag}> <td key={hashtag}><a href={hashtaglink} target="_blank">#{hashtag}</a></td> <td><span className="emphasizedText">{user.hashtags[hashtag]}</span></td> </tr> ); })} </tbody> </table> </div> </div> <div className = "Split Split-Diversity"> <div className = "Card-Content Split-Content"> <div className = "descriptor"> Edits by the Numbers </div> <PieChart user={user} /> </div> <div className = "Card-Content Split-Content"> <div className = "Stats-Item"> <img src="assets/graphics/staticons/Edit.svg" width="50px"></img> <div className="Stat-Info"> <p><span className="emphasizedNumber">{total}</span></p> <p>Total Edits</p> </div> </div> <div className = "Stats-Item"> <img src="assets/graphics/staticons/Changeset.svg" width="50px"></img> <div className="Stat-Info"> <p><span className="emphasizedNumber">{changesetCount}</span></p> <p>Changesets</p> </div> </div> <div className = "Stats-Item"> <img src="assets/graphics/staticons/Building.svg" width="50px"></img> <div className="Stat-Info"> <p><span className="emphasizedNumber">{total_buildings}</span></p> <p>Buildings</p> </div> </div> <div className = "Stats-Item"> <img src="assets/graphics/staticons/POI.svg" width="50px"></img> <div className="Stat-Info"> <p><span className="emphasizedNumber">{Number(user.total_poi_count_add)}</span></p> <p>Point of Interest</p> </div> </div> <div className = "Stats-Item"> <img src="assets/graphics/staticons/Road.svg" width="50px"></img> <div className="Stat-Info"> <span className="emphasizedNumber small" style={this.state.kmStatsStyle}> {' ' + total_road_km + 'km'} </span> <p>Roads</p> </div> </div> <div className = "Stats-Item"> <img src="assets/graphics/staticons/Water.svg" width="50px"></img> <div className="Stat-Info"> <span className="emphasizedNumber small" style={this.state.kmStatsStyle} > {' ' + total_waterway_km + 'km'} </span> <p>Waterways</p> </div> </div> </div> </div> <div className ="Stat-Component-Container"> <ContributionBox timestamps={user.edit_times} /> <div className = "descriptor"> WORLD REACH </div> <div className = "Split Split-WorldReach"> <table className = "table-curve"> <tbody> <tr> <th><span>Countries most mapped</span></th> <th></th> </tr> {R.take(11, countries).map(function (country) { var countryName = country[0]; if (country[0] === 'Democratic Republic of the Congo') { countryName = 'DR Congo'; } else if (country[0] === 'United States of America') { countryName = 'USA'; } else if (country[0] === 'French Southern and Antarctic Lands') { countryName = 'ATF'; } else if (country[0] === 'United Republic of Tanzania') { countryName = 'Tanzania'; } else if (country[0] === 'Central African Republic') { countryName = 'CAR'; } return ( <tr key={country[0]}> <td key={country[0]}>{countryName}</td> <td><span className="emphasizedText">{country[1]}</span></td> </tr> ); })} </tbody> </table> </div> <div className = "Split Split-Map"> <div id = "MapContainer"> <div className = "MapContent"> <div id="map"></div> </div> </div> </div> </div> </div> ); }
(currentIndex, tracks) => S.pipe([ R.reject(R.propEq('id', 'INIT')), R.take(currentIndex), R.takeLast(3), ])(tracks)
const s6: number = _.findIndex(x => x === '2', [ '1', '2' ]) const s7: number = _.findIndex(x => x === '2', { a:'1', b:'2' }) const forEachxs = _.forEach(x => console.log(x), ns) const groupedBy: {[k: string]: Array<number>} = _.groupBy(x => x > 1 ? 'more' : 'less' , ns) //$ExpectError const groupedBy1: {[k: string]: Array<string>} = _.groupBy(x => x > 1 ? 'more' : 'less')(ns) const groupedWith: Array<Array<number>> = _.groupWith(x => x > 1, ns) const groupedWith1: Array<Array<string>> = _.groupWith(x => x === 'one')(ss) const xOfXs: ?number = _.head(ns) const xOfXs2: ?number = _.head(ns) const xOfStr: string = _.head(str) const transducer = _.compose(_.map(_.add(1)), _.take(2)) const txs: Array<number> = _.into([], transducer, ns) //$ExpectError const txs1: string = _.into([], transducer, ns) //$ExpectError const txs2: string = _.into([], transducer, ss) const ind: number = _.indexOf(1, ns) const ind1: number = _.indexOf(str)(ss) const ind2:{[key: string]:{[k: string]: number|string}} = _.indexBy(x => 's', os) const ind3:{[key: string]:{[k: string]: number|string}} = _.indexBy(x => 's')(os) const insxs: Array<number> = _.insert(1, 2, ns) const insxs2: Array<string> = _.insert(1, '2', ss)
export const transitions = arr => R.reduce( addPair, R.of(R.take(2, arr)), R.takeLast(arr.length - 2, arr) );
timeout: 5000, headers: { "user-agent": "homeless-beta" // GitHub is happy with a unique user agent } }); github.authenticate({ type: 'oauth', token: config.apiToken, }); var findCommands = r.compose( r.map(r.compose(r.trim, r.drop(3))), r.filter(r.compose(r.equals('hb>'), r.take(3))) ) var dispatchCommand = (command) => { var split = r.split(' ', command); var name = split[0]; var args = split.slice(1); if (name !== 'clone') { throw Error('Unrecognised command:', name); } var repoRef = r.split('/', args[0]); var repoUser = repoRef[0]; var repoName = repoRef[1];
it('should work with take', function() { assert.equal('nacho', R.take(1, tuple)[0]); }
update(next) { return this.cursor === 0 ? new Undoable(R.takeLast(maxRevs, [...this.revs, next])) : new Undoable([...R.take(this.revs.length - this.cursor, this.revs), next]) }
import { repeat, take, splitAt, sortBy, prop, filter } from 'ramda'; import { handleActions } from 'redux-actions'; import { buildTrie, tokenizer } from '../parser/parser'; import heartOfDarkness from '../texts/heart-of-darkness'; // import dubliners from '../texts/dubliners'; const source = take(2000, tokenizer(heartOfDarkness)); // const source = take(2000, tokenizer(dubliners)); const srcFilter = repeat(true, source.length); const sourceTrie = buildTrie(source); const trieSort = sortBy(prop('i')); const initialState = { source, sourceTrie, filter: srcFilter, suggestions: [], cursor: 0, }; const selectFromFilter = (index, state) => { const [head, tail] = splitAt(index, state.filter); const [unchanged, alter] = splitAt(state.cursor, head); const alteredHead = unchanged.concat(repeat(false, alter.length)); return [alteredHead.length + 1, alteredHead.concat(tail)]; }; export const editor = handleActions({ SELECT_WORD: (state, action) => {
const BAR = CRLF + '°º¤ø,¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸,ø¤º°`°º¤ø,¸,ø¤º°`°º¤ø,¸,ø¤°º' + CRLF; const HOWTO = 'To participate, simply send a message to "thanksbot" on Slack!'; const FOOTER = [,,BAR,,`That's all for now, see you next week!`].join(CRLF); const wrap = wordwrap(2, 78); function formatEntry(entry) { const time = moment(entry.created_at).format('hh:mm A'); const heading = `[${time} EST] ${entry.sender} said:`; const message = wrap(emoji.emojify(entry.message), 80, `${CRLF} `); return CRLF + heading + CRLF + message; } const groupByEntryDate = R.groupBy(R.pipe( R.prop('created_at'), R.invoker(0, 'toISOString'), R.take(10) )); const formatEntries = R.map(formatEntry); export function prettyDate(date = new Date()) { return moment(date).format('MMMM Do, YYYY'); } // TODO: support arbitrary date ranges export function generate(thanks) { const groupedEntries = groupByEntryDate(thanks); const days = R.keys(groupedEntries); const welcome = `Welcome to the ${prettyDate()} edition of:`; const HEADER = [welcome,, LOGO,, HOWTO,].join(CRLF); const digest = R.reduce(function(log, date) { const dayHeading = moment(date).format('On dddd MMMM Do...');
const keyUpMod = (key, activeKeys) => take(indexOf(key, activeKeys), activeKeys)