程序员必做50题(1-15)—————— 程序员必做50题(16-30)
function rank(x){
var a = [3,6,9,15,20,88];
a[a.length] = x;
for(var i=0;i<a.length;i++){
for(var j=0;j<a.length;j++){
if(a[i]<a[j]){
var c = a[i];
a[i] = a[j];
a[j] = c;
}
}
}
return a;
}
console.log(rank(10));
var a = [10,11,12,13,14,15];
var b = [];
for(var i=0;a.length>0;a.length--){
b[i] = a[a.length-1]
i++;
}
console.log(b);
> 1
> 1 1
> 1 2 1
> 1 3 3 1
> 1 4 6 4 1
> 1 5 10 10 5 1
> 1 6 15 20 15 6 1
> ............
var a = []
for(var i=0;i<=10;i++){
a[i] = new Array(i+1);
}
for(var i=0;i<=10;i++){
for(var j=0;j<=i;j++){
if(j===0 || j===i){
a[i][j] = 1
}else{
a[i][j] = a[i-1][j-1]+a[i-1][j]
}
}
}
for(var i=0;i<=10;i++){
var b = '';
for(var j=0;j<=10-i-1;j++){
b += ' '
}
console.log(b+a[i])
}
var a = [8,12,87,56,32,46,5,48];
var max = a[0],x = 0;
var min = a[0],n = 0;
for(var i=0;i<a.length;i++){
if(max<a[i]){
max = a[i];
x = i;
}
if(min>a[i]){
min = a[i];
n = i;
}
}
var b = a[0];
a[0] = max;
a[x] = b;
var c = a[a.length-1];
a[a.length-1] = min;
a[n] = c;
console.log(a);
var n = [12,45,78,13,46,79,17,28,39,47];
var a = n.splice(-5);
console.log(a.concat(n));
function num(x){
var a = '';
for(var i=1,k=0;k<=x;){
k++;
if(i===3){
i = 0;
a += '第 '+k+' 位';
}
i++;
}
return a;
}
console.log(num(10));
function main(x){
return '输入字符串的长度为:'+x.length;
}
console.log(main('qwertyuiop'));
function a(x){
var sum = 0;
for(var i=x;i>1;i-=2){
sum += 1/i;
}
return sum;
}
console.log(a(7));
for(var i=1;;i++){
var hou=0;
for(var j=1,res=i,get=0;j<=5;j++){
get=(res-1)*0.2;
res=(res-1)*0.8;
if(get%1!=0){
break;
}
tag+=1;
}
if(hou==5){
console.log('海滩上原来最少有'+i+'个桃子');
break;
}
}
for(var i=10;i<=99;i++){
if(8*i>=10&&8*i<=99&&9*i>=100&&9*i<=999){
console.log('??代表的两位数是'+i);
console.log('809*??的结果'+809*i);
}
}
var num1=425;
var num2=0;
num1=num1.toString();
for(var i=num1.length-1,root=1;i>=0;i--){
num2+=Number(num1[i])*root;
root*=8;
}
console.log(num2);
var i =0;
for(var a=0;a<=7;a++){
for(var b=0;b<=7;b++){
for(var c=0;c<=7;c++){
for(var d=0;d<=7;d++){
for(var e=0;e<=7;e++){
for(var f=0;f<=7;f++){
for(var g=0;g<=7;g++){
var aa = a*1000000;
var bb = b*100000;
var cc = c*10000;
var dd = d*1000;
var ee = e*100;
var ff = f*10;
var sum = aa+bb+cc+dd+ee+ff+g;
if(sum%2!==0){
i++;
}
}
}
}
}
}
}
}
console.log(i);
var a = 150;
if(a%2!==0){
console.log('不是偶数');
}else{
var aa = a/2;
var bb = aa;
aa-1===0 ? aa = 1 : aa--;
bb+1===2 ? bb = 1 : bb++;
console.log(a+'='+aa+'+'+bb);
}
var a = 45;
if(a%2===0){
console.log('不是素数');
}else{
if(a%9!==0){
console.log(a+' 小于9,不能被9整除');
}else{
console.log(a+' 可以被 '+a/9+' 个9整除')
}
}
var a = '6572';
var aa = [];
var c;
var d = '';
for(var i=0;i<4;i++){
aa[i] = (Number(a[i])+5)%10;
}
c = aa[0];
aa[0] = aa[3];
aa[3] = c;
c = aa[1];
aa[1] = aa[2];
aa[2] = c;
for(var i=0;i<4;i++){
d += Number(aa[i])
}
console.log(d)
新手上路,望各位大佬指教-----------
如有相关资料、视屏给作者看看可否?
45道已全部更新-------------------------
[email protected]
欢迎提各种意见----------------------------------------------------------------------------------------------------------------------- 学WEB前端的第17天
程序员必做50题(1-15)—————— 程序员必做50题(16-30)