本文整理汇总了TypeScript中lodash.range函数的典型用法代码示例。如果您正苦于以下问题:TypeScript range函数的具体用法?TypeScript range怎么用?TypeScript range使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了range函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
const hakuVastaus = function(vastaus) {
$scope.perusteet = vastaus;
$scope.nykyinenSivu = $scope.perusteet.sivu + 1;
$scope.hakuparametrit.sivukoko = $scope.perusteet.sivukoko;
$scope.sivuja = $scope.perusteet.sivuja;
$scope.kokonaismaara = $scope.perusteet.kokonaismäärä;
$scope.sivut = _.range(0, $scope.perusteet.sivuja);
pat = new RegExp("(" + $scope.hakuparametrit.nimi + ")", "i");
};
示例2: toString
public toString() : string {
let res = '' // 'Goal ' + this.goalId + '\n\n'
this.goalHyp.forEach(h => {
res += h + '\n'
})
_.range(80).forEach(() => { res += '-' })
res += '\n' + this.goalCcl
return res
}
示例3: withIndex
function withIndex(callCluster: sinon.SinonStub, opts: any = {}) {
const defaultIndex = {
'.kibana_1': {
aliases: { '.kibana': {} },
mappings: {
doc: {
dynamic: 'strict',
properties: {
migrationVersion: { dynamic: 'true', type: 'object' },
},
},
},
},
};
const defaultAlias = {
'.kibana_1': {},
};
const { numOutOfDate = 0 } = opts;
const { alias = defaultAlias } = opts;
const { index = defaultIndex } = opts;
const { docs = [] } = opts;
const searchResult = (i: number) =>
Promise.resolve({
_scroll_id: i,
_shards: {
successful: 1,
total: 1,
},
hits: {
hits: docs[i] || [],
},
});
callCluster.withArgs('indices.get').returns(Promise.resolve(index));
callCluster.withArgs('indices.getAlias').returns(Promise.resolve(alias));
callCluster
.withArgs('reindex')
.returns(Promise.resolve({ task: 'zeid', _shards: { successful: 1, total: 1 } }));
callCluster.withArgs('tasks.get').returns(Promise.resolve({ completed: true }));
callCluster.withArgs('search').returns(searchResult(0));
_.range(1, docs.length).forEach(i => {
callCluster
.withArgs('scroll')
.onCall(i - 1)
.returns(searchResult(i));
});
callCluster
.withArgs('scroll')
.onCall(docs.length - 1)
.returns(searchResult(docs.length));
callCluster.withArgs('bulk').returns(Promise.resolve({ items: [] }));
callCluster
.withArgs('count')
.returns(Promise.resolve({ count: numOutOfDate, _shards: { successful: 1, total: 1 } }));
}
示例4: test
test('it should assign colors deterministically', () => {
const lessons: Lesson[] = [];
range(NUM_DIFFERENT_COLORS).forEach((i) => {
// Add 2 lessons for this ith venue
const newLesson = { ...bareLesson, venue: `LT${i}` };
lessons.push(newLesson);
lessons.push(newLesson);
});
const coloredLessons = colorLessonsByKey(lessons, 'venue');
range(NUM_DIFFERENT_COLORS * 2).forEach((i) => {
const coloredLesson = coloredLessons[i];
const index = Math.floor(i / 2);
expect(coloredLesson).toMatchObject(bareLesson); // Ensure that existing lesson info wasn't modified
expect(coloredLesson).toHaveProperty('venue', `LT${index}`);
expect(coloredLesson).toHaveProperty('colorIndex', index % NUM_DIFFERENT_COLORS);
});
});
示例5: getTrainingSet
async function getTrainingSet() {
const peopleArray = await of(...range(5, 10), 2)
.pipe(map(x => `https://swapi.co/api/people/?format=json&page=${x}`))
.pipe(flatMap(x => Axios.get(x).catch(console.error)))
.pipe(map((x: AxiosResponse) => x.data))
.pipe(reduce((acc: any[], x: any) => [x, ...acc], []))
.toPromise();
console.log(JSON.stringify(peopleArray, null, 2));
}
示例6: it
it('should merge snippets if necessary', () => {
const lines = keyBy(
range(4, 23)
.concat(range(38, 43))
.map(line => mockSourceLine({ line })),
'line'
);
const snippets = [
[lines[4], lines[5], lines[6], lines[7], lines[8]],
[lines[38], lines[39], lines[40], lines[41], lines[42]],
[lines[17], lines[18], lines[19], lines[20], lines[21]]
];
const result = expandSnippet({ direction: 'down', lines, snippetIndex: 0, snippets });
expect(result).toHaveLength(2);
expect(result[0].map(l => l.line)).toEqual(range(4, 22));
expect(result[1].map(l => l.line)).toEqual(range(38, 43));
});
示例7: appData
function appData(state: any = { list: [] }, action) {
switch(action.type) {
case GET_LIST:
return {
list: _.range(20)
};
}
return state;
}
示例8: uploadMulti
uploadMulti() {
let files = this.selectedFiles
if (_.isEmpty(files)) return;
let filesIndex = _.range(files.length)
_.each(filesIndex, (idx) => {
this.currentUpload = new Upload(files[idx]);
this.upSvc.pushUpload(this.currentUpload)}
)
}
示例9: weekRangeToArray
export function weekRangeToArray(weekRange: WeekRange) {
return _.range(weekRange.startWeek, weekRange.endWeek + 1).filter(w => {
return weekRange.oddEven === 0
? true
: weekRange.oddEven === 1
? w % 2 === 1
: weekRange.oddEven === 2
? w % 2 === 0
: false;
});
}
示例10: makeList
function makeList(values: Array<string>, power: number, start = 0) {
return _.map(
_.range(start, values.length + start),
function(i) {
return {
label: values[i - start],
value: Math.pow(power, i)
};
}
);
}
示例11:
_.each(_.range(height), col => {
let blankCount = 0;
_.each(_.range(1, height - row), adder => {
if (orbs[row + adder][col] === '\u241a') {
blankCount += 1;
};
});
if (blankCount > 0) {
blanksBelow[`${row}, ${col}`] = blankCount;
};
});
示例12: testModel
() => {
async.each(
_.range(3),
(i: number, callback: Function) => {
let item = new testModel({ name: 'item' + (5 - i), index: (5 - i) });
item.save(() => {
callback();
});
},
done);
});
示例13: sameBodyAndType
function sameBodyAndType(hyp1 : HTMLElement, hyp2 : HTMLElement) : boolean {
const children1 = $(hyp1).children().slice(1)
const children2 = $(hyp2).children().slice(1)
if (children1.length !== children2.length) { return false }
for (const i in _.range(children1.length)) {
if ($(children1[i]).html() !== $(children2[i]).html()) {
return false
}
}
return true
}
示例14: it
it('should setTimeslot', function () {
const schedule = new Schedule();
assert.throw(() => { schedule.setTimeslots([false]); }, 'timeslot should be 24 in length');
const timeslots: boolean[] = Array<boolean>(24);
_.forEach(_.range(24), (i) => timeslots[i] = false);
timeslots[0] = true;
schedule.setTimeslots(timeslots);
assert.equal(schedule.toJSON(), 1, 'should allow setting timeslot in array of boolean');
});
示例15: cart2sph
/**
* Convert cartesian coordinates to spherical coordinates
*
* @param x - array of x coordinates
* @param y - array of y coordinates
* @param z - arrya of z coordinates
*/
function cart2sph(x: number[], y: number[], z: number[]) {
var range = _.range(x.length)
var r = range.map(i => Math.sqrt(x[i] * x[i] + y[i] * y[i] + z[i] * z[i]))
var elev = range.map(i => Math.atan2(z[i], Math.sqrt(x[i] * x[i] + y[i] * y[i])))
var az = range.map(i => Math.atan2(y[i], x[i]))
return {
r: r,
elev: elev,
az: az
}
}