SOURCE

/*一公司使用字符串来记录考勤,首行输入的数字代表接下来需要判断的员工数,
  后面每一行代表一个员工的出勤记录,每行不超过 10000 个字符,每个单词代表每天的出勤情况,
  present 代表正常出勤,absent 代表缺席,late 代表迟到,leaveearly 代表早退,单词之间用空格隔开。
  如下所示:
  如下所示:
    present
    present present

    现需要判断每个员工是否能获得全勤奖, 获得全勤奖的规则是:缺勤不超过 1 次,没有连续的迟到 / 早退,
    任意连续 7 天内出现缺勤 / 迟到 / 早退的次数不超过 3 次。

    输出要求:结果输出为一行,以空格隔开
    示例 1:
    输入:
    present
    present present
    输出:
    true true
    示例 2:
    present
    absent present late present present present present leaveearly late present present
*/




function isFullPresent(input) {
    let inputArr = input.split(' ');
    //缺勤超过1次
    let rule1 = 0,sumCount = [],flag='yes',unflag='no';
    //连续Flag
    let lateFlag = 0, leaveearlyFlag=0;
    for(let i = 0; i<inputArr.length; i++){
        if(inputArr[i]=='absent'){
            rule1++;
            sumCount.push(unflag);
             if(rule1>1){
                return false;
            }
        }        
        if(inputArr[i]=='late'){
            sumCount.push(unflag);
            lateFlag++;
            if(lateFlag>=2){
                return false
            }
        }else if(inputArr[i]=='leaveearly'){
            sumCount.push(unflag);
            leaveearlyFlag++;
            if(leaveearlyFlag>=2){
                return false
            }
        }else{
            lateFlag = 0;
            leaveearlyFlag=0;
            sumCount.push(flag);
        }
    }
   
    let rule3 = 0;
    for(let i = 0;i<sumCount.length; i++){
        if(sumCount[i]=='no'){
            rule3= rule3 + 1;
            if(rule3 >=3){
                return false;
            }
        }else if(i%7==0){
            rule3 = 0;
        }
    }
    return true;
}

const input1 = 'present';
const input2 = 'present present';
const input3 = 'absent present late present present present present leaveearly late  present present';
console.log(isFullPresent(input1));
console.log(isFullPresent(input2));
console.log(isFullPresent(input3));

console 命令行工具 X clear

                    
>
console