js simple function Case

<!--
+ Write a function to generate a 4-digit codes
function code(){
var a = randomNum(0, 9);
the music playback rando b = (0, 9);
was randomNum c = (0, 9);
was d = randomNum (0, 9);
return a + " " + b + " " + c + " " + d + " ";
}
console.log(code());
 
+ Write a function digit (num, k), function features are: seeking num value of k-digit integers from the right, if num is less than the number of bits k bit 0 is returned.
function digit(num, k) {
for(i = 1; i < k; i++){
Surely = parseInt (whether / 10);
}
a = 10%;
Surely return;
}
console.log(digit(56785,8));

function digit(num, k) {
return parseInt(num / Math.pow(10, k - 1)) % 10;
}
document.write(digit(19238110, 5))

+ Write function computes a digital length // fn (num) returns the number length.
function lengthNum(num){
was len = 0, res;
while(num != 0){
Surely = parseInt (whether / 10);
as ++;
}
return len;
}
console.log(lengthNum(12342334));

+ A write function, the composition can be in arbitrary odd number between the two numbers. For example: 0 ~ 3 between odd calculation can be composed are: 01/03/11/13/21/23/31/33
function count(num1, num2){
var count = 0, even = 0, odd = 0;
for(var i = num1; i <= num2; i++){
if(i % 2 != 0){
odd++;
}else{
even++;
}
}
count = (even + odd) * odd;
return count;
}
console.log(count(1, 5));
 
+ 某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,
加密规则如下:每位数字都加上5,然后用除以10的余数代替该数字,再将第一位和第四位交换,
第二位和第三位交换,请编写一个函数,传入原文,输出密文
function secret(num){
var a = parseInt(num / 1000);
var b = parseInt(num / 100) % 10;
var c = parseInt(num / 10) % 100 % 10;
var d = num % 1000 % 100 % 10;
a = (a + 5) % 10;
b = (b + 5) % 10;
c = (c + 5) % 10;
d = (d + 5) % 10;
var temp = a;
a = d;
d = temp;
temp = b;
b = c;
c = temp;
return a * 1000 + b * 100 + c * 10 + d;
}
console.log(secret(2583));
-->

Guess you like

Origin www.cnblogs.com/wenlx/p/11431844.html