如何在地图运算符 ES6 中执行条件



我需要检查map函数中的一个条件,为个位数值预置零,这意味着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);
;}
}

演示:在此处输入链接说明

[...this.times]=x.map(i=>{
if ( condition ) {
i = '0'+i;
}
return i;
});

谢谢亚历山大·斯塔罗塞尔斯基,我打错了字。

最新更新