本文整理匯總了TypeScript中Immutable.OrderedSet類的典型用法代碼示例。如果您正苦於以下問題:TypeScript OrderedSet類的具體用法?TypeScript OrderedSet怎麽用?TypeScript OrderedSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了OrderedSet類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('unions a set and an iterable and returns a set', () => {
var s1 = Set([1,2,3]);
var emptySet = Set();
var l = List([1,2,3]);
var s2 = s1.union(l);
var s3 = emptySet.union(l);
var o = OrderedSet([1,2,3]);
var s4 = s1.union(o);
var s5 = emptySet.union(o);
expect(Set.isSet(s2)).toBe(true);
expect(Set.isSet(s3)).toBe(true);
expect(Set.isSet(s4) && !OrderedSet.isOrderedSet(s4)).toBe(true);
expect(Set.isSet(s5) && !OrderedSet.isOrderedSet(s5)).toBe(true);
});
示例2: List
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;
});
示例3: it
it('provides initial values in a mixed order', () => {
var s = OrderedSet.of('C', 'B', 'A');
expect(s.has('A')).toBe(true);
expect(s.has('B')).toBe(true);
expect(s.has('C')).toBe(true);
expect(s.size).toBe(3);
expect(s.toArray()).toEqual(['C','B','A']);
});
示例4: toggleSetItem
function toggleSetItem(state: OrderedSet<string>, id: string): OrderedSet<string> {
return state.includes(id) ? state.remove(id) : state.add(id);
}
示例5: 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;
});
}
};