本文整理匯總了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);