百度编程题[倒计时+字典序]

倒计时:100%
function addZero(value){
    if(value>=10){
        return value;
    }
    return '0'+value;
}

function second( second_time ){
    var data = {
        second : 0, 
        min : 0, 
        hour : 0,
        day : 0
    };
    data.second = parseInt(second_time);
    if( parseInt(second_time )>= 60){
        var second = parseInt(second_time) % 60;
        var min = parseInt(second_time / 60);
        data.second = second;  data.min = min;
        if( min >= 60 ){  min = parseInt(second_time / 60) % 60;
            var hour = parseInt( parseInt(second_time / 60) /60 );
            data.min = min;
            data.hour = hour;
             if( hour >= 24 ){
                hour = parseInt( parseInt(second_time / 60) /60 ) % 24;
                var day = parseInt( parseInt( parseInt(second_time / 60) /60 ) / 24 );
                data.hour = hour;  data.day = day;  }
        }
    }
    return data;
}  


function render(data){
    var ele = document.getElementById('jsCountdown');
    if(data.day){
        ele.children[0] = addZero(data.day)+'天';  }else{
        ele.children[0].className = 'hide';
    }
    ele.children[1] = addZero(data.hour)+':';
    ele.children[2] = addZero(data.min) + ':';
    ele.children[3] = addZero(data.second);
}


字典序:100%
var firstStr=readline();

var secondStr=readline();

var firstArr=firstStr.split('');
var secondArr=secondStr.split('');

secondArr.sort();
secondArr.reverse();
for(var i=0;i<secondArr.length;i++){
    for(var x=0;x<firstArr.length;x++){
        if(secondArr[i]>firstArr[x]){
            firstArr[x]=secondArr[i];
            secondArr.splice(i,1);
        }
    }
}

print (firstArr.join(''));

#百度##前端工程师#
全部评论
我第一题是 60% 不知出了什么差错,先贴出来再看看 function second(second) {     if (!second || second < 0) {         second = 0;     }     return {         day: Math.floor(second / (24 * 60 * 60)),         hour: Math.floor(second / (60 * 60)) % 24,         min: Math.floor(second / 60) % 60,         second: second % 60     }; } function render(data) {     var countdown = document.getElementById('jsCountdown');     if (!countDown) {         throw '#jsCountdown not exists.';     }     var daySpan = countDown.children[0],         hourSpan = countDown.children[1],         minSpan = countDown.children[2],         secondSpan = countDown.children[3];     var renderText = function (elem, val, append) {         append || (append = '');         var paddedVal = (val < 10 ? '0' + val : '' + val);         elem.innerHTML = paddedVal + append;     }     if (!+data['day']) {         daySpan.classList.add('hide');     } else {         renderText(daySpan, data['day'], '天');     }     renderText(hourSpan, data['hour'], ':');     renderText(minSpan, data['min'], ':');     renderText(secondSpan, data['second']); }
点赞 回复 分享
发布于 2017-09-19 22:08
前端的题型是什么样的,只是考前端还是?
点赞 回复 分享
发布于 2017-09-19 22:15

相关推荐

点赞 评论 收藏
分享
一颗宏心:华为HR晚上过了十二点后还给我法消息。
点赞 评论 收藏
分享
评论
点赞
5
分享
牛客网
牛客企业服务