7.28
// n位数逆转
function rNumber(n){
let m = 0;
for(; n > 0 ;){
m = m * 10 + n % 10
n = parseInt(n / 10)
}
return m;
}
console.log(rNumber(45156153135)) ;
// 打印菱形、空心菱形,行数做参数
function rhombus(rowCount){
if(rowCount <= 0 || rowCount % 2 == 0){
return;
}
for(let i = 1; i <= rowCount ; i++){
let line = '';
let blankCount = Math.abs(Math.ceil(rowCount / 2) - i);
for(let j = 1; j <= blankCount ; j++){
line += ' ';
}
//4 3 2 1 2 3 4
//1 2 3 4 3 2 1
//1 3 5 7 5 3 1
let startCount = (Math.ceil(rowCount / 2) - blankCount) * 2 - 1;
for(let j = 1 ; j <= startCount; j++){
line += '*'
}
console.log(line);
}
return;
}
rhombus(11)