程式設計編碼 小tips~~~
阿新 • • 發佈:2018-11-13
//精確計算,日期+迴圈 var start=new Date().getTime(); do{ var end=new Date().getTime(); } while(end-start<2000); console.log("上段程式碼"+(end-start)+"毫秒");
時間的精確計算~~可以用於一些小Demo的測試
//返回介於0到1之間一個隨機數,不包括0和1。 //值=Math.floor(Math.random()*(最後一個值-第一個值+1)+第一個值) function select(start,end) { var total=end-start+1;return Math.floor(Math.random()*total+start); }
返回隨機數
//隨機生成不重複的陣列 var num=5; var arr=[]; function select(start,end){ var total=end-start+1; return Math.floor(Math.random()*total+start); } while(num>0){ var randomNumber=select(1,100); if(arr.indexOf(randomNumber)===-1){ arr.push(randomNumber); num--; } } console.log(arr);
typeof Symbol() //"symbol" typeof Number() //"number" typeof String() //"string" typeof Function() //"function" typeof Object() //"object" typeof Boolean() //"boolean" typeof null //"object" typeof undefined //"undefined"
// 改變原陣列的方法 : push,pop,unshift,shift,reverse,sort,splice