本文整理汇总了TypeScript中lodash.times函数的典型用法代码示例。如果您正苦于以下问题:TypeScript times函数的具体用法?TypeScript times怎么用?TypeScript times使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了times函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: timelineSeries
timelineSeries(count = 8) {
const offsets = shuffle(times(count, (index) => index));
const labels = [['Confort', 'icon-bed'],
['Eco', 'icon-leaf'],
['Night', 'icon-moon'],
['Game', 'icon-gamepad'],
['Recreation', 'icon-keyboard'],
['Visit', 'icon-stethoscope'],
['Work', 'icon-briefcase'],
['Shopping', 'icon-shopping-bag']];
return times(count, (index) => {
const offset = offsets.pop();
const title = labels.pop();
const date = new Date().getTime();
const seeek = random(-72, 72);
const begin = date + (seeek * 10000);
return {
data: this.getDataSeries(begin, offset),
lineWidth: 10,
name: {
title: title[0],
icon: title[1]
}
};
});
}
示例2: group
group(end => {
// construct a set of mocked responses that each
// returns an author with a different id (but the
// same name) so we can populate the cache.
const mockedResponses: MockedResponse[] = [];
times(count, index => {
const result = cloneDeep(originalResult);
result.data.author.id = index;
const variables = cloneDeep(originalVariables);
variables.id = index;
mockedResponses.push({
request: { query, variables },
result,
});
});
const client = new ApolloClient({
networkInterface: mockNetworkInterface(...mockedResponses),
addTypename: false,
dataIdFromObject,
});
// insert a bunch of stuff into the cache
const promises = times(count, index => {
return client
.query({
query,
variables: { id: index },
})
.then(result => {
return Promise.resolve({});
});
});
const myBenchmark = benchmark;
const myAfterEach = afterEach;
Promise.all(promises).then(() => {
myBenchmark(
{
name: `read single item from cache with ${count} items in cache`,
count,
},
done => {
const randomIndex = Math.floor(Math.random() * count);
client
.query({
query,
variables: { id: randomIndex },
})
.then(result => {
done();
});
},
);
end();
});
});
示例3: it
it('should combine websocket frame chunks', async () => {
const port = newFirebaseServer();
const client = newFirebaseClient(port);
await client.set({
foo: _.times(2000, String),
});
assert.deepEqual((await server.getValue()), {
foo: _.times(2000, String),
});
});
示例4: randomIndex
export function randomIndex(len: number): number[] {
let indexArr: number[] = [];
let retArr: number[] = [];
let r: number;
_.times(len, (i) => {
indexArr.push(i);
});
_.times(len, (i) => {
r = _.random(len - 1 - i);
retArr.push(indexArr[r]);
_.pullAt(indexArr, r);
});
return retArr;
}
示例5: scheduler
export function scheduler({ originTime,
intervalSeconds,
lowerBound,
upperBound }: SchedulerProps): Moment[] {
if (!intervalSeconds) { // 0, NaN and friends
return [originTime];
}
upperBound = upperBound || nextYear();
// # How many items must we skip to get to the first occurence?
let skip_intervals =
Math.ceil((lowerBound.unix() - originTime.unix()) / intervalSeconds);
// # At what time does the first event occur?
let first_item = originTime
.clone()
.add((skip_intervals * intervalSeconds), "seconds");
let list = [first_item];
times(60, () => {
let x = last(list);
if (x) {
let item = x.clone().add(intervalSeconds, "seconds");
if (item.isBefore(upperBound)) {
list.push(item);
}
}
});
return list;
}
示例6: sampleMany
export function sampleMany(n: number = 1, attributes: any): Array<Model> {
return _.times(n, n => {
let compiledAttributes: any = sampleRaw(attributes, n);
return new Model(compiledAttributes);
});
}
示例7: getClientInstance
done => {
const promises: Promise<void>[] = [];
const client = getClientInstance();
times(count, () => {
promises.push(
new Promise<void>((resolve, reject) => {
client
.watchQuery({
query: simpleQuery,
fetchPolicy: 'cache-only',
})
.subscribe({
next(res: ApolloQueryResult<Object>) {
if (Object.keys(res.data).length > 0) {
resolve();
}
},
});
}),
);
});
client.query({ query: simpleQuery });
Promise.all(promises).then(() => {
done();
});
},
示例8: it
it("sets up the spy", () => {
_.times(10, () => {
const expectedResult: number = Math.random();
const result: any = underTest.andReturn(expectedResult).instance.foo();
expect(result).toBe(expectedResult);
});
});
示例9: ARGB
export const web = _.flatten(_.times(6, (r) => {
return _.flatten(_.times(6, (g) => {
return _.times(6, (b) => {
return new ARGB(255, r * 51, g * 51, b * 51);
});
}));
}));