我想制作班次解析器助手,它是生成工作班次的时间,下面是班次规则
let shift_rule = [
{
shift: '07-12',
start: 7,
finish: 12
},
{
shift: '12-17',
start: 12,
finish: 17
},
{
shift: '17-22',
start: 17,
finish: 22
},
];
如果时移是timeStart = 7,timeFinish = 17
预期输出:
[
{
shift: '07-12',
start: 7,
finish: 12
},
{
shift: '12-17'
start: 12,
finish: 17
},
]
我已经尝试用这段代码解决
shift_rule
.map((time) => ((timeFinish > time.start)) && time)
.filter(item => typeof item !== 'boolean');
但是当 filter 是time.start = 17,时timeFinish = 22,它显示:
[
{
shift: '07-12',
start: 7,
finish: 12
},
{
shift: '12-17',
start: 12,
finish: 17
},
{
shift: '17-22',
start: 17,
finish: 22
},
]
希望可以用ES6 Functional解决
慕容708150
相关分类