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


TypeScript ramda.findIndex函數代碼示例

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


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

示例1: findIndex

 .reduceRight((updatedArray, el) => {
   /**
    * We need to update in place to maintain the correct timeline of events. Update in-place
    * by finding the index then updating at that index.
    */
   const indexOfFoundEvent = findIndex(({ id }) => id === el.id, updatedArray);
   return indexOfFoundEvent > -1
     ? update(indexOfFoundEvent, el, updatedArray)
     : [el, ...updatedArray];
 }, prevArr)
開發者ID:displague,項目名稱:manager,代碼行數:10,代碼來源:event.helpers.ts

示例2: sum

  // sum :: [Number] → Number
  sum(filed, list) {
    return R.compose(R.sum, R.pluck(filed))(list)
  },
  // pluck :: Functor f => k → f {k: v} → f v
  pluck(filed, list) {
    return R.pluck(filed)(list)
  },
  // filter :: Filterable f => (a → Boolean) → f a → f a
  filter(fn, list) {
    return R.filter(fn, list)
  },
  // findIndex :: (a → Boolean) → [a] → Number
  findIndex(field, val, list) {
    return R.findIndex(R.propEq(field, val))(list)
  },
  // concat :: [a] → [a] → [a]
  concat(listA, listB) {
    return R.concat(listA, listB)
  },
  //flatten :: [a] → [b]
  flatten(list) {
    return R.flatten(list)
  },

  //// [{}] ////
  // getFullObjByField :: k -> [a] -> [a] -> {k:v}
  getFullObjByField(findField, partArr, fullArr) {
    return R.filter(R.where({ [findField]: R.contains(R.__, partArr) }))(fullArr)  // tslint:disable-line
  },
開發者ID:stefaniepei,項目名稱:react-redux-scaffold,代碼行數:30,代碼來源:ramda.ts

示例3: cleanOperators

export function cleanOperators(tokens: IToken[]) {
  const output: IToken[] = [];
  let temp: IToken[] = [];
  let bracketsCount = 0;

  tokens.forEach((token) => {
    const { image } = token;

    if (bracketsCount === 0 && image !== '(' && image !== ')') {
      output.push(token);
      return;
    }

    temp.push(token);
    if (image === '(') {
      bracketsCount += 1;
    } else if (image === ')') {
      bracketsCount -= 1;

      if (bracketsCount === 0) {
        // recursive clean within parenthesis, unnests one layer
        const cleaned = cleanOperators(temp.slice(1, -1));
        if (cleaned.length) {
          // Length check means this is fine
          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
          output.push(R.head(temp)!, ...cleaned, R.last(temp)!);
        }
        temp = [];
      }
    }
  });

  const findFirstRelevant = R.findIndex(
    (token: IToken) => MODULE_REGEX.test(token.image) || token.image === '(',
  );
  const findLastRelevant = R.findLastIndex(
    (token: IToken) => MODULE_REGEX.test(token.image) || token.image === ')',
  );

  const processedTokens = output.slice(findFirstRelevant(output), findLastRelevant(output) + 1);

  const removedDuplicates = processedTokens.filter((item, pos, arr) => {
    // always keep the first and last element
    if (pos === 0 || pos === arr.length - 1) return true;

    // then check if each element is different than the one before it
    return !(AND_OR_REGEX.test(item.image) && AND_OR_REGEX.test(arr[pos + 1].image));
  });

  const moduleTokens = [];
  // Falsy value if array does not contain unique conjunction
  // Need token to inject later on when it is missing between two modules
  const singularConjunction = removedDuplicates.reduce(
    (acc: IToken | null | false, token: IToken) => {
      const { image } = token;
      if (image === 'and' || image === 'or') {
        if (!acc) return token;
        if (acc.image !== image) return false;
      }
      return acc;
    },
    null,
  );

  // Fill in missing values with conjunction found
  for (let i = 0; i < removedDuplicates.length; i++) {
    const token = removedDuplicates[i];
    const nextToken = removedDuplicates[i + 1];
    const isModule = MODULE_REGEX.test(token.image);
    const isAnotherModule = nextToken && MODULE_REGEX.test(nextToken.image);

    moduleTokens.push(token);
    if (singularConjunction && isModule && isAnotherModule) {
      moduleTokens.push(singularConjunction);
    }
  }

  return moduleTokens;
}
開發者ID:nusmodifications,項目名稱:nusmods,代碼行數:79,代碼來源:parseString.ts


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