阿里巴巴2016校园招聘 前端开发工程师(一)

1.实现如下页面布局。核心区域左侧自适应,右侧固定宽度200px

这里写图片描述

html结构:

<body>
    <header class="header clearf">
        <div class="logo"></div>
        <span class="username">用户名</span>
    </header>
    <aside class="aside"></aside>
    <article class="content"></article>
    <footer class="footer"></footer>
</body>

css代码:

html,body,div,article,aside,footer,header{
            margin:0;
            padding:0;
        }
        .clearf{
            zoom:1;/*ie6/7清除浮动*/
        }
        .clearf:after{
            content:'';
            display: block;
            clear:both;
            height:0;
            visibility: 0;
        }
        .header{
            margin-bottom:10px;
            position: relative;
            background: #f5f5f5;
        }
        .logo{
            margin:10px;
            width: 100px;
            height: 100px;
            background: #f00;
            float:left;
        }
        .username{
            position: absolute;
            right:10px;
            bottom:10px;
        }
        .aside{
            width: 200px;
            float:right;
            height:400px;
            background: #ff0;
        }
        .content{
            margin-right:220px;
            height:400px;
            background: #f0f;
        }
        .footer{
            margin-top: 10px;           
        }

2.请实现一个fibonacci函数,要求其参数和返回值如下所示:
/**
 *@desc: fibonacci
 *@param: count {Number}
 *@return: result {Number} 第count个fibonacci值,计数从0开始
  fibonacci数列为:[1, 1, 2, 3, 5, 8, 13, 21, 34 …]
  则getNthFibonacci(0)返回值为1
  则getNthFibonacci(4)返回值为5
 */
function getNthFibonacci(count) {
}

答案:
此题应该避免使用递归的方法,因为当count较大时,递归的方法耗时较长。
故考虑使用迭代法,可以使用数组记录每一项。
但此题只需要用到前面两项,从节约空间的角度讲不需要开辟数组。

JS代码:

function getNthFibonacci(n){
            if(n==0||n==1) return 1;
            var first = 1;
            var second = 1;
            var third = 0;
            for(var i=2;i<=n;i++){
                third = first + second;
                first = second;
                second = third;
            }
            return third;
        }

3.填写内容让下面代码支持a.name = “name1”; b.name = “name2”:
function obj(name){
    (1)
}
obj.(2) = "name2";
var a = obj("name1");
var b = new obj;

答案:

1. if(name) this.name = name;
2. prototype.name

(工厂函数与构造函数)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值