可能的面试题
数组拷贝
var a = [a, b, c], b; # 1、数组遍历 b = new Array(); for (var i = 0; i < a.length; i++) { b.push(a[i]); } # 2、concat() b = [].concat(a); # 3、slice b = a.slice(0)
求n到m之间的随机整数的公式
random = Math.floor(Math.random()*(m-n+1)+n);
function getRandom(min, max) { var choise = max-min+1; // 随机整数的个数 return Math.floor(Math.random()*choise+min); } var random = getRandom(2, 6);
求50天后是星期几
第一种方法:
var today = new Date(); today.setDate(today.getDate()+50) today.getDay()
第二种方法:
var today = new Date(); var year = today.getFullYear(); var month = today.getMonth()+1; var date = today.getDate(); var temp1 = new Date(year+5, month, date) var temp2 = new Date(year, month+5, date) var temp3 = new Date(year, month, date+50) temp1.getDay() temp2.getDay() temp3.getDay()
1
略懂,略懂....