• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript Immutable.OrderedSet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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);
 });
开发者ID:Harishs84,项目名称:immutable-js,代码行数:14,代码来源:Set.ts


示例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;
      });
开发者ID:Ethan826,项目名称:tablexi-coding-challenge,代码行数:31,代码来源:knapsack.ts


示例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']);
 });
开发者ID:Harishs84,项目名称:immutable-js,代码行数:8,代码来源:OrderedSet.ts


示例4: toggleSetItem

function toggleSetItem(state: OrderedSet<string>, id: string): OrderedSet<string> {
  return state.includes(id) ? state.remove(id) : state.add(id);
}
开发者ID:threehams,项目名称:reverie-client,代码行数:3,代码来源:uiReducer.ts


示例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;
      });
    }
  };
开发者ID:Ethan826,项目名称:tablexi-coding-challenge,代码行数:73,代码来源:knapsack.ts



注:本文中的Immutable.OrderedSet类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript Immutable.Record类代码示例发布时间:2022-05-25
下一篇:
TypeScript Immutable.OrderedMap类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap