本文整理匯總了TypeScript中src/utils/fast.fastMap函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript fastMap函數的具體用法?TypeScript fastMap怎麽用?TypeScript fastMap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了fastMap函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
export const filterTableColumns = (
data: string[][],
fieldOptions: FieldOption[]
): string[][] => {
const visibility = {}
const filteredData = fastMap<string[], string[]>(data, (row, i) => {
return fastFilter<string>(row, (col, j) => {
if (i === 0) {
const foundField = fieldOptions.find(
field => field.internalName === col
)
visibility[j] = foundField ? foundField.visible : true
}
return visibility[j]
})
})
return filteredData[0].length ? filteredData : [[]]
}
示例2: Set
export const sortTableData = (
data: string[][],
sort: SortOptions
): {sortedData: string[][]; sortedTimeVals: string[]} => {
const headerSet = new Set(data[0])
let sortIndex = 0
if (headerSet.has(sort.field)) {
sortIndex = _.indexOf(data[0], sort.field)
}
const dataValues = _.drop(data, 1)
const sortedData = [
data[0],
..._.orderBy<string[][]>(dataValues, sortIndex, [sort.direction]),
] as string[][]
const sortedTimeVals = fastMap<string[], string>(
sortedData,
(r: string[]): string => r[sortIndex]
)
return {sortedData, sortedTimeVals}
}