How to use the underscore.map function in underscore

To help you get started, we’ve selected a few underscore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kartotherian / kartotherian / test / Job.js View on Github external
tiles: tiles
                });
                assert.equal(job.size, size, 'size');

                job.cleanupForQue();
                assert.deepEqual(job._encodedTiles, expected, 'encoded');

                let encjob = newJob({
                    zoom: zoom,
                    _encodedTiles: job._encodedTiles
                });

                assert.equal(encjob.size, size, 'size2');
                let expectedDecoded = _.reject(tiles, v => Array.isArray(v) && v[0] === v[1]);
                // Remove empty ranges
                expectedDecoded = _.map(expectedDecoded, v => Array.isArray(v) && v[0] === v[1] + 1 ? v[0] : v);
                assert.deepEqual(encjob.tiles, expectedDecoded, 'roundtrip');
            } catch(err) {
                err.message = msg + ': ' + err.message;
                throw err;
            }
        };
github Khan / perseus / src / util / fix-passage-refs.jsx View on Github external
var FixPassageRefs = itemData => {
    if (itemData._multi) {
        // We're in a multi-item. Don't do anything, just return the original
        // item data.
        return itemData;
    }

    var newQuestion = fixRendererPassageRefs(itemData.question);
    var newHints = _.map(itemData.hints, hint => fixRendererPassageRefs(hint));
    return _.extend({}, itemData, {
        question: newQuestion,
        hints: newHints,
    });
};
github nrkno / tv-automation-server-core / meteor / lib / Rundown.ts View on Github external
}),
			'_id')

		// the SuperTimeline has an issue with resolving pieces that start at the 0 absolute time point
		// we therefore need a constant offset that we can offset everything to make sure it's not at 0 point.
		const TIMELINE_TEMP_OFFSET = 1

		// create a lookup map to match original pieces to their resolved counterparts
		let piecesLookup: IPieceExtendedDictionary = {}
		// a buffer to store durations for the displayDuration groups
		const displayDurationGroups: _.Dictionary = {}

		let startsAt = 0
		let previousPart: PartExtended
		// fetch all the pieces for the parts
		partsE = _.map(parts, (part, itIndex) => {
			let partTimeline: SuperTimeline.TimelineObject[] = []

			// extend objects to match the Extended interface
			let partE: PartExtended = extendMandadory(part, {
				pieces: _.map(Pieces.find({ partId: part._id }).fetch(), (piece) => {
					return extendMandadory(piece, {
						renderedDuration: 0,
						renderedInPoint: 0
					})
				}),
				renderedDuration: 0,
				startsAt: 0,
				willProbablyAutoNext: (
						(previousPart || {}).autoNext || false
					) && (
						(previousPart || {}).expectedDuration !== 0
github CodeboxIDE / codebox / src / core / cb.files.sync / environment.js View on Github external
Environment.prototype.usersInfo = function() {
    // Get infornmation on every use in the environment
    return _.map(this.users, function(user) {
        return user.info();
    });
};
github 26medias / node-nlpsum / node_modules / nlpsum / nlpsum.js View on Github external
// Now we sort the sentences by weight
	structure.ordered = structure.sentences.sort(function(a, b) {
		return b.data.weights.total-a.data.weights.total;
	});
	
	// We only keep the top N (=quota)
	structure.keep	= structure.ordered.slice(0, quota);
	
	// And now we reorder by index
	structure.indexed = structure.keep.sort(function(a, b) {
		return a.index-b.index;
	});
	
	// Finally, we join the sentences
	structure.summary = _.map(structure.indexed, function(sentence) {
		return sentence.text;
	});
	
	return {
		data:	structure,
		text:	structure.summary.join('\n')
	}
	
}
github okfn / opendatasurvey / lib / util.js View on Github external
exports.markupRows = function (datasets) {
  return _.map(datasets, function (dataset) {
    return exports.markup(dataset);
  });
};
github CartoDB / cartodb / lib / assets / javascripts / cartodb3 / components / form-components / editors / fill / input-ramp / ramp-list-view.js View on Github external
_setupCollection: function () {
    var ramps = [];

    if (this._customRampList) {
      ramps = _.map(this._customRampList.models, function (ramp) {
        return { name: ramp.get('name'), val: ramp.get('val') };
      }, this);
    } else {
      ramps = _.map(rampList, function (ramp, name) {
        return { name: name, val: ramp[this._bins] };
      }, this);
    }

    this._collection = new CustomListCollection(ramps);
  },
github itchio / itch / src / renderer / components / collections-grid / row.tsx View on Github external
render() {
    const { collection } = this.props;
    const { title } = collection;

    const games = map(collection.collectionGames, cg => cg.game);

    const gameItems = map(games, (game, index) => {
      const { coverUrl, stillCoverUrl } = game;
      return (
        
      );
    });

    const cols: JSX.Element[] = [];
    each(gameItems, (item, i) => {
github dai-shi / continuation.js / src / continuation.js View on Github external
root.deep_clone = function(node) {
  if (node instanceof Date) {
    return node;
  } else if (node instanceof RegExp) {
    return node;
  } else if (Array.isArray(node)) {
    return _.map(node, root.deep_clone);
  } else if (node instanceof Object) {
    return _.object(_.map(_.pairs(node), function(x) {
      return [x[0], root.deep_clone(x[1])];
    }));
  } else {
    return node;
  }
};
github oroinc / platform / src / Oro / Bundle / UserBundle / Resources / public / js / components / role / capability-set-component.js View on Github external
const groups = _.map(options.data, function(group) {
                group.items = _.map(group.items, function(item) {
                    item.editable = !options.readonly;
                    return item;
                });
                if (options.readonly) {
                    group.items = _.map(group.items, function(item) {
                        item.editable = !options.readonly;
                        item.noAccess = item.access_level === accessLevels.NONE;
                        return item;
                    });
                }
                const itemsCollection = new BaseCollection(group.items, {
                    model: PermissionModel
                });
                this.listenTo(itemsCollection, 'change', _.bind(this.onAccessLevelChange, this, group.group));
                return _.extend({}, group, {
                    editable: !options.readonly,