當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript underscore.reduce函數代碼示例

本文整理匯總了TypeScript中underscore.reduce函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript reduce函數的具體用法?TypeScript reduce怎麽用?TypeScript reduce使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了reduce函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: AddBusVisitItem

    AddBusVisitItem(bookingId, alkhidmatCentre, driver, bus, fuelAmount) {
        if (bus == undefined || bus.length <= 0) {
            helper.ShowModalPopup("danger", "Bus Info", "Please enter valid  vehicle no.!");
            return;
        }
        else if (fuelAmount == "" || fuelAmount == undefined || fuelAmount === 0) {
            helper.ShowModalPopup("danger", "Bus Info", "Please enter valid amount!");
            return;
        }
        
        var counter = this.idCounter++;
        var busExist = this.backboneCollection.findWhere({ busId: bus.id });
        var driverExist = this.backboneCollection.findWhere({ driverId: driver.id });

        

        if (busExist == undefined && driverExist == undefined) {
            this.backboneCollection.push(new busVisitDto.Models.BusVisitDto({
                busVisitId: counter,
                centreId: alkhidmatCentre.id, centreDesc: alkhidmatCentre.description,
                busId: bus.id, busDesc: bus.description,
                driverId: driver.id, driverDesc: driver.description,
                visitTypeId: "2",
                //isAvailableForBooking: false,
                //isAvailableForFutureBooking: false,
                bookingId: bookingId,
                fuelAmount: fuelAmount.replace(",","")
            }));
            
            this.busVisitCollectionView.collection = this.backboneCollection;

            var sum = _.reduce(this.backboneCollection.models, (memo, item) => memo + parseFloat(item.get("fuelAmount").replace(",","")), 0);
            this.paymentView.viewModel.amount(helper.FormatMoney(sum));
        }
        else {
            helper.ShowModalPopup("danger", "Bus Info", "Entry already exists!");
        }

    }
開發者ID:saeed-ahmed,項目名稱:CCTracking,代碼行數:39,代碼來源:PaymentCtrl.ts

示例2: function

import * as _ from "underscore";
var sum = _.reduce([1, 2, 3], function(memo, num){ return memo + num; }, 0);
console.log(sum);
開發者ID:chun4foryou,項目名稱:develop,代碼行數:3,代碼來源:test-underscore.ts

示例3: RemoveBusVisitItem

 RemoveBusVisitItem(busId, centreId, driverId) {
     this.backboneCollection.remove(this.backboneCollection.findWhere({ busId: busId, centreId: centreId, driverId: driverId }));
     var sum = _.reduce(this.backboneCollection.models, (memo, item) => memo + parseFloat(item.get("fuelAmount").replace(",","")), 0);
     this.paymentView.viewModel.amount(helper.FormatMoney(sum));
 }
開發者ID:saeed-ahmed,項目名稱:CCTracking,代碼行數:5,代碼來源:PaymentCtrl.ts

示例4: getBuckets

      return getBuckets().then((buckets) => {
        const reservations: MoveReservations = {};
        if (settings.farming.makeRoomForItems) {
          // reserve one space in the active character
          reservations[this.store.id] = {};
          makeRoomTypes.forEach((type) => {
            reservations[this.store.id][buckets.byId[type].type!] = 1;
          });
        }

        return _.reduce(
          items,
          (promise, item) => {
            // Move a single item. We do this as a chain of promises so we can reevaluate the situation after each move.
            return promise
              .then(() => {
                const vault = D1StoresService.getVault()!;
                const vaultSpaceLeft = vault.spaceLeftForItem(item);
                if (vaultSpaceLeft <= 1) {
                  // If we're down to one space, try putting it on other characters
                  const otherStores = D1StoresService.getStores().filter(
                    (store) => !store.isVault && store.id !== this.store.id
                  );
                  const otherStoresWithSpace = otherStores.filter((store) =>
                    store.spaceLeftForItem(item)
                  );

                  if (otherStoresWithSpace.length) {
                    if ($featureFlags.debugMoves) {
                      console.log(
                        'Farming initiated move:',
                        item.amount,
                        item.name,
                        item.type,
                        'to',
                        otherStoresWithSpace[0].name,
                        'from',
                        D1StoresService.getStore(item.owner)!.name
                      );
                    }
                    return dimItemService.moveTo(
                      item,
                      otherStoresWithSpace[0],
                      false,
                      item.amount,
                      items,
                      reservations
                    );
                  }
                }
                if ($featureFlags.debugMoves) {
                  console.log(
                    'Farming initiated move:',
                    item.amount,
                    item.name,
                    item.type,
                    'to',
                    vault.name,
                    'from',
                    D1StoresService.getStore(item.owner)!.name
                  );
                }
                return dimItemService.moveTo(item, vault, false, item.amount, items, reservations);
              })
              .then(() => {
                if (incrementCounter) {
                  this.itemsMoved++;
                }
              })
              .catch((e) => {
                if (e.code === 'no-space') {
                  outOfSpaceWarning(this.store);
                } else {
                  toaster.pop('error', item.name, e.message);
                }
                throw e;
              });
          },
          $q.resolve()
        );
      });
開發者ID:bhollis,項目名稱:DIM,代碼行數:81,代碼來源:farming.service.ts

示例5: subtract

function subtract($all) {
    enforce($all).isArray().isNotEmpty();
    return _.reduce($all, (memo, num) => memo - num);
}
開發者ID:pumlhorse,項目名稱:pumlhorse,代碼行數:4,代碼來源:math.ts

示例6: getFields

 getFields() {
   return _.reduce(this.templates, (fields: string[], template: Template) => fields.concat(template.getFields()), []);
 }
開發者ID:erocheleau,項目名稱:search-ui,代碼行數:3,代碼來源:TemplateList.ts

示例7: add

function add($all) {
    enforce($all).isArray().isNotEmpty();
    return _.reduce($all, (memo, num) => memo + num);
}
開發者ID:pumlhorse,項目名稱:pumlhorse,代碼行數:4,代碼來源:math.ts

示例8: multiply

function multiply($all) {
    enforce($all).isArray().isNotEmpty();
    return _.reduce($all, (memo, num) => memo * num);
}
開發者ID:pumlhorse,項目名稱:pumlhorse,代碼行數:4,代碼來源:math.ts

示例9: reduce

 .sortBy(key => {
   const total = reduce(rankingInfo.termsWeight[key].Weights, (memo, value) => memo + value, 0);
   return total;
 })
開發者ID:coveo,項目名稱:search-ui,代碼行數:4,代碼來源:RankingInfoTable.ts

示例10: fn

export function sum<T>(list: T[], summer: _.ListIterator<T, number>): number {
  const fn = _.iteratee(summer) as _.ListIterator<T, number>;
  return _.reduce(list, (memo, val, index) => {
    return memo + fn(val, index, list);
  }, 0);
}
開發者ID:delphiactual,項目名稱:DIM,代碼行數:6,代碼來源:util.ts


注:本文中的underscore.reduce函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。