(()=>{
function getArr1(value:number,count:number):number[]{
const arr:number[] = []
for(let i = 0 ;i<count;i++){
arr.push(value)
}
return arr;
}
const arr1 = getArr1(100.123,3)
console.log(arr1[0].toFixed(2));
function getArr2(value:string ,count:number):string []{
const arr:string [] = []
for(let i = 0 ;i<count;i++){
arr.push(value)
}
return arr;
}
const arr2 = getArr2("我循环",3)
console.log(arr2);
function getArr3<T>(value:T,count:number):T[]{
const arr:T[] = []
for(let i = 0;i<count;i++){
arr.push(value)
}
return arr;
}
const a1 = getArr3<number>(100.123,3)
const a2 = getArr3<string>("我也循环",3)
console.log(a1[0].toFixed(2));
console.log(a2[0].split(""));
})()
|