今日头条前端编程题

 

 

 

 

var p=0;
  var l=2;
  var str = new String("hello world");
  document.writeln(str+"<br />");
  document.writeln(str.replace(str.substr(p,l),strReverse(str.substr(p,l),"")));
  function strReverse(str1,str2){
    var length = str1.length;
    for(var i=length-1;i>=0;i--){
      str2+=str1.charAt(i);
    }

    return str2;
  }

 

var p=0;
var l=2;
var str = new String("hello world");
document.writeln(str+"<br />");
document.writeln(str.replace(str.substr(p,l),strReverse(str.substr(p,l),"")));
function strReverse(str1,str2){
var length = str1.length;
for(var i=length-1;i>=0;i--){
str2+=str1.charAt(i);
}
return str2;
}

 

 

 1   var n = 7;
 2   var s = 2;
 3   var l=6;
 4    var songNum = Math.floor((l+1)/(s+1)) >n?n:Math.floor((l+1)/(s+1));
 5    if(songNum % 13 == 0){
 6      songNum -=1;
 7    }
 8 
 9    cdNum =Math.ceil( n/songNum );
10    if( (n%songNum) !=0 && (n%songNum)%13==0 && (songNum-(n%songNum))==1 ){
11      cdNum+=1;
12    }
13    document.writeln(cdNum);

 

posted @ 2017-09-13 17:22  vector11248  阅读(329)  评论(0编辑  收藏  举报