倒计时
function gettimer(y,m,d){
var now_date = new Date().getTime();
var future_date = new Date(y,m,d).getTime();
var cha = future_date - now_date;
var day = Math.floor( cha / 1000 / 60 / 60 / 24);
var hours = Math.floor(cha / 1000 / 60 / 60 % 24);
var minuters = Math.floor(cha / 1000 / 60 % 60);
var seconds = Math.floor(cha / 1000 % 60);
console.log(seconds);
return `${day < 10 ? '0' + day : day}天${hours}时${minuters}分${seconds < 10 ? '0' + seconds : seconds}秒`;
}
var h1 = document.getElementById('time');
var nt = gettimer(2019,12,30);
h1.innerHTML = nt;
setInterval(() => {
var nt = gettimer(2019,12,30);
h1.innerHTML = nt;
}, 1000);
console.log(gettimer(2019,12,30));
判断字符串是否对称
var arr = 'aahhba';
function isSame(list){
if(list.length % 2 != 0){
return ;
}
for(var i = 0; i < list.length; i++){
if(list.charAt(i) !== list.charAt(list.length - 1 -i)){
return 'no';
}
}
return 'ok';
}
console.log(isSame(arr));
冒泡(数组)
var arr = [24,22,3,44,9];
for(var i = 0; i < arr.length; i++){
for(var j = 0; j < arr.length;j++){
if(arr[j] > arr[j + 1]){
var newarr = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = newarr;
}
}
}
console.log(arr);