本文整理汇总了TypeScript中d3-array.pairs函数的典型用法代码示例。如果您正苦于以下问题:TypeScript pairs函数的具体用法?TypeScript pairs怎么用?TypeScript pairs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pairs函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should return empty and non-empty consecutive buckets', async () => {
const start = EARLIEST_TIME_WITH_DATA;
const end = LATEST_TIME_WITH_DATA + (LATEST_TIME_WITH_DATA - EARLIEST_TIME_WITH_DATA);
const bucketSize = Math.ceil((end - start) / 10);
const {
data: {
source: { logSummaryBetween },
},
} = await client.query<any>({
query: logSummaryBetweenQuery,
variables: {
start,
end,
bucketSize,
},
});
expect(logSummaryBetween).to.have.property('buckets');
expect(logSummaryBetween.buckets).to.have.length(10);
expect(
logSummaryBetween.buckets.filter((bucket: any) => bucket.entriesCount > 0)
).to.have.length(5);
expect(
pairs(
logSummaryBetween.buckets,
(first: any, second: any) => first.end === second.start
).every(pair => pair)
).to.equal(true);
});
示例2: Uint8ClampedArray
crossed = d3Array.cross<string, number>(readonlyChars, readonlyNums);
strArray = d3Array.cross<number, number, string>([2, 3] as ReadonlyArray<number>, new Uint8ClampedArray([5, 6]), (a, b) => (a + b) + 'px');
strArray = d3Array.cross([2, 3] as ReadonlyArray<number>, new Uint8ClampedArray([5, 6]), (a, b) => {
const aa: number = a;
const bb: number = b;
return (aa + bb) + 'px';
});
d3Array.cross(new Uint8Array([1, 2, 3, 4, 5]), new Uint8Array([10, 20, 30, 40, 50]));
// pairs() ---------------------------------------------------------------------
let pairs: Array<[MixedObject, MixedObject]>;
pairs = d3Array.pairs(mergedArray);
numbersArray = d3Array.pairs<MixedObject, number>(mergedArray, (a, b) => b.num - a.num);
numbersArray = d3Array.pairs(mergedArray, (a, b) => {
const aa: MixedObject = a;
const bb: MixedObject = b;
return bb.num - aa.num;
});
const readonlyMergedArray = mergedArray as ReadonlyArray<MixedObject>;
pairs = d3Array.pairs(readonlyMergedArray);
numbersArray = d3Array.pairs<MixedObject, number>(readonlyMergedArray, (a, b) => b.num - a.num);
numbersArray = d3Array.pairs(readonlyMergedArray, (a, b) => {
const aa: MixedObject = a;
const bb: MixedObject = b;
示例3: return
crossed = d3Array.cross(['x', 'y'], [1, 2]);
crossed = d3Array.cross<string, number>(['x', 'y'], [1, 2]);
let strArray: string[] = d3Array.cross<number, number, string>([2, 3], [5, 6], (a, b) => (a + b) + 'px');
strArray = d3Array.cross([2, 3], [5, 6], (a, b) => {
let aa: number = a;
let bb: number = b;
return (aa + bb) + 'px';
});
// pairs() ---------------------------------------------------------------------
let pairs: Array<[MixedObject, MixedObject]>;
pairs = d3Array.pairs(mergedArray);
numbersArray = d3Array.pairs<MixedObject, number>(mergedArray, (a, b) => b.num - a.num);
numbersArray = d3Array.pairs(mergedArray, (a, b) => {
let aa: MixedObject = a;
let bb: MixedObject = b;
return bb.num - aa.num;
});
// permute() -------------------------------------------------------------------
// getting a permutation of array elements
mergedArray = d3Array.permute(mergedArray, [1, 0, 2, 5, 3, 4, 6]);
// Getting an ordered array with object properties
示例4: MixedObject
new MixedObject(50, new Date(2016, 9, 30)),
]
];
let mergedArray: MixedObject[];
mergedArray = d3Array.merge(testArrays); // inferred type
mergedArray = d3Array.merge<MixedObject>(testArrays); // explicit type
// mergedArray = d3.merge<MixedObject>([[10, 40, 30], [15, 30]]); // fails, type mismatch
// pairs() ---------------------------------------------------------------------
let pairs: Array<[MixedObject, MixedObject]>;
pairs = d3Array.pairs(mergedArray);
// permute() -------------------------------------------------------------------
// getting a permutation of array elements
mergedArray = d3Array.permute(mergedArray, [1, 0, 2, 5, 3, 4, 6]);
// Getting an ordered array with object properties
let testObject = {
val: 10,
name: 'Test',
when: new Date(),
more: [10, 30, 40]
};
示例5: pairs
const isSorted = <Value>(comparator: (first: Value, second: Value) => number) => (
values: Value[]
) => pairs(values, comparator).every(order => order <= 0);