先給大家放下我?guī)煾附o我布置的作業(yè)嘶居,晚點(diǎn)會給大家放答案和詳解
? ? 1,求斐波那契數(shù)列的第10鲫趁,30歪今,50項(xiàng)(已知遞推公式 F(n+2)= F(n+1) + F(n),F(1) = F(2) = 1)
? ? ? // 第一題
? ? ? ? function fibonacci (n) {
? ? ? ? ? ? let f1 = 1,f2 = 1;
? ? ? ? ? ? let fn;
? ? ? ? ? ? // 在此寫代碼铣猩。怎虫。股毫。
? ? 2,對象數(shù)組排序膳音,按score的值從小到大的順序。
? ? ? ? // 第二題
? ? ? ? var arr = [{name :'o',score :18},{name :'c',score :12},{name :'x',score :11},{name :'l',score :19},{name :'a',score :22}];
? ? ? ? // 在此寫代碼铃诬。祭陷。。
? ? 3,凍結(jié)obj對象趣席,使之可讀但不可寫兵志。(能訪問它的屬性,但無法改變值)
// 第三題
? ? ? ? var obj = {
? ? ? ? ? ? a:1,
? ? ? ? ? ? b:'2',
? ? ? ? ? ? c:{
? ? ? ? ? ? ? ? d:3
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? // 在此寫代碼宣肚。想罕。。
? ? 4,將一個(gè)時(shí)間戳顯示成 yyyy-MM-dd-hh-mm 的格式霉涨,如 2018-11-26-10-14
? ? ? // 第四題
? ? ? ? var timestemp = 1543198531709;
? ? ? ? // 在此寫代碼按价。。笙瑟。
? ? 5,將字符串urlParam解析成對象
// 第五題
? ? ? ? var urlParam = 'action=machine_query&biz=計(jì)費(fèi)日志&bizrole=VPC日志ODPS代理&group_keys=region,sm_name'
? ? ? ? // 應(yīng)該會變成這樣:{
? ? ? ? //? ? action:'machine_query',
? ? ? ? //? ? biz:'計(jì)費(fèi)日志',
? ? ? ? //? ? bizrole:'VPC日志ODPS代理',
? ? ? ? //? ? group_keys:'region,sm_name'
? ? ? ? // }
? ? ? ? // 在此寫代碼楼镐。。逮走。
? ? 6,判斷this指向
? ? ? ? // 第六題
? ? ? ? function Monkey (name,age) {
? ? ? ? ? ? this.name = name;
? ? ? ? ? ? this.age = age;
? ? ? ? ? ? // this指向誰鸠蚪?
? ? ? ? }
? ? ? ? Monkey.prototype.eat = function(){
? ? ? ? ? ? console.log(this.name + ' has ate a banana')
? ? ? ? ? ? // this指向誰今阳?
? ? ? ? }
? ? ? ? Monkey.prototype.sayHello = function(){
? ? ? ? ? ? setTimeout(function(){
? ? ? ? ? ? ? ? this.alert('hello friend, enjoy your test!')
? ? ? ? ? ? ? ? // this指向誰师溅?
? ? ? ? ? ? },0)
? ? ? ? }
? ? ? ? var hzw = new Monkey('hzw','18')
? ? ? ? hzw.angry = function () {
? ? ? ? ? ? console.warn('am ' + this.name + ' and am angry , and i will not talk to you anymore')
? ? ? ? ? ? // this指向誰?
? ? ? ? }
? ? ? ? hzw.eat()
? ? ? ? hzw.sayHello()
? ? ? ? hzw.angry()