本文整理汇总了TypeScript中underscore.sortBy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sortBy函数的具体用法?TypeScript sortBy怎么用?TypeScript sortBy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sortBy函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1:
const itemsByType = _.mapObject(_.groupBy(engrams, 'type'), (items) => {
// Sort exotic engrams to the end so they don't crowd out other types
items = _.sortBy(items, (i) => {
return i.isExotic ? 1 : 0;
});
// No more than 9 engrams of a type
return _.first(items, 9);
});
开发者ID:bhollis,项目名称:DIM,代码行数:8,代码来源:auto-loadouts.ts
示例2:
.then(data => {
data.Items.forEach(idea => {
items.push(
ideaPrePostProcessor.PostProcess(idea, user)
);
});
return _.sortBy(items, (item) => ((-1 * item.likeCount) + (-2 * item.teamCount)));
});
开发者ID:hakant,项目名称:HackathonPlannerAPI,代码行数:9,代码来源:IdeaRepository.ts
示例3: reject
}, (err: any, response: any) => {
if (err || !response.ok) {
reject(err)
} else {
let channels = response.channels.filter((c: any) => c.is_member && !c.is_archived)
channels = _.sortBy(channels, "name")
const reformatted: IChannel[] = channels.map((channel: any) => ({id: channel.id, label: `#${channel.name}`}))
resolve(reformatted)
}
})
开发者ID:DipJar,项目名称:looker-slackbot,代码行数:10,代码来源:slack_service.ts
示例4: sortByComments
public sortByComments() {
var posts = _.sortBy(this.rootScope.posts, (p: RedditPost) => p.numberOfComments);
if (this.commentsSortAsc) {
this.commentsSortAsc = false
this.rootScope.posts = posts
} else {
this.commentsSortAsc = true
this.rootScope.posts = posts.reverse()
}
}
开发者ID:RookieOne,项目名称:ng-reddit-example,代码行数:10,代码来源:post-filters.ts
示例5: _getMaxReview
_getMaxReview(ratingsAndReviews: RatingAndReview[]) {
const orderedRatingsAndReviews = _.sortBy(ratingsAndReviews, (ratingAndReview) => (ratingAndReview.ratingCount < 2 ? 0
: ratingAndReview.averageReview)).reverse();
if ((orderedRatingsAndReviews.length > 0) &&
(orderedRatingsAndReviews[0].ratingCount > 1)) {
return orderedRatingsAndReviews[0];
}
return null;
}
开发者ID:delphiactual,项目名称:DIM,代码行数:11,代码来源:d2-perkRater.ts
示例6: search
search(searchText: string, documentationList: ILivingDocumentation[]):
{ documentationList: ILivingDocumentation[]; searchContext: ISearchContext; } {
const searchContext = getSearchContext(searchText);
documentationList = _.filter(
_.map(documentationList, d => isTextPresentInDocumentation(searchContext, d)), d => !!d);
documentationList = _.sortBy(documentationList, d => d.definition.sortOrder);
return {
documentationList: documentationList,
searchContext: searchContext
};
}
开发者ID:eugene-sea,项目名称:LivingDocumentation,代码行数:11,代码来源:search.service.ts
示例7: getUDSources
async getUDSources(pubkey:string) {
const reducables = await this.query('SELECT * FROM ' + this.table + ' s1 ' +
'WHERE conditions = ? ' +
'AND s1.tx IS NULL ' +
'ORDER BY op ASC', ['SIG(' + pubkey + ')']);
const reduced = Indexer.DUP_HELPERS.reduceBy(reducables, ['identifier', 'pos']).map((src) => {
src.type = src.tx ? 'T' : 'D';
return src;
});
return _.sortBy(reduced, (row:SindexEntry) => row.type == 'D' ? 0 : 1);
}
开发者ID:Kalmac,项目名称:duniter,代码行数:11,代码来源:SIndexDAL.ts
示例8: searchForSimilarItem
/**
* Find an item in store like "item", excluding the exclusions, to be equipped
* on target.
* @param exclusions a list of {id, hash} objects that won't be considered for equipping.
* @param excludeExotic exclude any item matching the equippingLabel of item, used when dequipping an exotic so we can equip an exotic in another slot.
*/
function searchForSimilarItem(item: DimItem, store: DimStore, exclusions: DimItem[] | undefined, target: DimStore, excludeExotic: boolean): DimItem | null {
const exclusionsList = exclusions || [];
let candidates = store.items.filter((i) => {
return i.canBeEquippedBy(target) &&
i.location.id === item.location.id &&
!i.equipped &&
// Not the same item
i.id !== item.id &&
// Not on the exclusion list
!_.any(exclusionsList, { id: i.id, hash: i.hash });
});
if (!candidates.length) {
return null;
}
if (excludeExotic) {
candidates = candidates.filter((c) => c.equippingLabel !== item.equippingLabel);
}
// TODO: unify this value function w/ the others!
const sortedCandidates = _.sortBy(candidates, (i) => {
let value = {
Legendary: 4,
Rare: 3,
Uncommon: 2,
Common: 1,
Exotic: 0
}[i.tier];
if (item.isExotic && i.isExotic) {
value += 5;
}
if (i.primStat) {
value += i.primStat.value / 1000;
}
return value;
}).reverse();
return sortedCandidates.find((result) => {
if (result.equippingLabel) {
const otherExotic = getOtherExoticThatNeedsDequipping(result, store);
// If there aren't other exotics equipped, or the equipped one is the one we're dequipping, we're good
if (!otherExotic || otherExotic.id === item.id) {
return true;
} else {
return false;
}
} else {
return true;
}
}) || null;
}
开发者ID:delphiactual,项目名称:DIM,代码行数:59,代码来源:dimItemService.factory.ts
示例9: setupTextcomplete
function setupTextcomplete() {
if (textcomplete) {
textcomplete.destroy();
textcomplete = null;
}
const editor = new Textarea($element[0].getElementsByTagName('input')[0]);
textcomplete = new Textcomplete(editor);
textcomplete.register(
[
{
words: searchConfig.keywords,
match: /\b([\w:]{3,})$/i,
search(term, callback) {
if (term) {
let words = this.words.filter((word: string) => word.includes(term.toLowerCase()));
words = _.sortBy(words, (word: string) => word.indexOf(term.toLowerCase()));
if (term.match(/\b((is:|not:|tag:|notes:|stat:)\w*)$/i)) {
callback(words);
} else if (words.length) {
callback([term, ...words]);
} else {
callback([]);
}
}
},
// TODO: use "template" to include help text
index: 1,
replace(word) {
word = word.toLowerCase();
return word.startsWith('is:') && word.startsWith('not:') ? `${word} ` : word;
}
}
],
{
zIndex: 1000
}
);
textcomplete.on('rendered', () => {
if (textcomplete.dropdown.items.length) {
// Activate the first item by default.
textcomplete.dropdown.items[0].activate();
}
});
$scope.$on('$destroy', () => {
if (textcomplete) {
textcomplete.destroy();
textcomplete = null;
}
});
}
开发者ID:bhollis,项目名称:DIM,代码行数:52,代码来源:search-filter.component.ts
注:本文中的underscore.sortBy函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论