我需要在map函数中检查一个条件,在单个数字值前加上0,这意味着00.00到09.30的剩余值是相同的。
当前,它是所有值的前缀。
代码:
export class SelectOverviewExample implements OnInit {
days=[];
times =[];
ngOnInit(){
[...this.days] = weekdays;
// [...this.times]=IntervalTime;
this.OnCall();
}
OnCall(){
var toInt = time => ((h,m) => h*2 + m/30)(...time.split(':').map(parseFloat)),
toTime = int => [Math.floor(int/2), int%2 ? '30' : '00'].join(':'),
range = (from, to) => Array(to-from+1).fill().map((_,i) => from + i),
eachHalfHour = (t1, t2) => range(...[t1, t2].map(toInt)).map(toTime);
let x=[];
[...x]= eachHalfHour('0:00','15:30');
[...this.times]=x.map(i=>'0'+i);
;}
}发布于 2018-09-07 04:50:14
[...this.times]=x.map(i=>{
if ( condition ) {
i = '0'+i;
}
return i;
});谢谢Alexander Staroselsky,我打错了。
https://stackoverflow.com/questions/52211947
复制相似问题