本文整理汇总了TypeScript中Immutable.OrderedSet.toList方法的典型用法代码示例。如果您正苦于以下问题:TypeScript OrderedSet.toList方法的具体用法?TypeScript OrderedSet.toList怎么用?TypeScript OrderedSet.toList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Immutable.OrderedSet
的用法示例。
在下文中一共展示了OrderedSet.toList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: computeHelper
private computeHelper(
prices: OrderedSet<number>,
budget: number): any { // actually Set<List<number>>
let hashed = this.hashArgs(prices, budget);
let memoizedResult = this.memo[hashed];
if (typeof memoizedResult !== "undefined") {
return memoizedResult;
}
// Base cases
// If there are no prices, there can be no solution. Return empty set.
if (prices.size === 0) {
let results = Set([]);
this.memo[hashed] = results;
return results;
// With one price, return empty set if price is not a factor of budget
// or return a list of length budget / price filled with price.
// E.g., for price 2 and budget 8, return List([2, 2, 2, 2]).
} else if (prices.size === 1) {
let onlyElement = prices.toList().get(0);
if (budget % onlyElement === 0) {
let results = Set([List(Array(budget / onlyElement).fill(onlyElement))]);
this.memo[hashed] = results;
return results;
} else {
let results = Set([]);
this.memo[hashed] = results;
return results;
}
// Recursive case. Divide-and-conquer algorithm compiles and filters
// results by recurring on each price price, subtracting that price
// from the budget and filtering the list of price prices to be less
// than or equal to both the new budget and the current price. See
// README for additional information.
} else {
return prices.flatMap((price: number) => {
let newBudget = budget - price; // If we buy this item, what is our new budget?
// Remove items that are more than our budget and more than the item
// under consideration.
let newMenuItems = prices.filter(c => {
let priceCeiling = Math.min(newBudget, price);
return c <= priceCeiling;
}) as OrderedSet<number>; // Should remain an OrderedSet after filter
// No recursion if the item under consideration exactly zeroes our
// budget.
if (newBudget === 0) {
let results = List([List([price])]);
this.memo[hashed] = results;
return results;
};
// Recursive call
let recursive = this.computeHelper(newMenuItems, newBudget);
// If recursion returned results, concat the item under consideration
// onto each result and return that. If recursion didn't return results
// return empty set.
let results = recursive
? recursive.map((e: List<number>) => e.concat(price)).toSet()
: OrderedSet([]);
this.memo[hashed] = results;
return results;
});
}
};