面试 面试 flex 数组高阶api

​ 今天遇到两个外包公司真实的面试题,方向给大家,欢迎大家提出宝贵意见!
一、CSS 自适应布局


HTML
<div class="client-a">
   <div class="client-b"></div>
   <div class="client-b"></div>
   <div class="client-b"></div>
   <div class="client-b"></div>
   <div class="client-b"></div>
   ...
</div>

<style>
</style>
        上面就是这道面试题,基本上考的就是了解一下我们对于Flex布局掌握的程度,足以看出Flex布局的重要性!!!下面是实现的代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .a {
            min-width: 1000px;
            padding: 24px;
            border: 1px solid #333;
            display: flex;
            justify-content: space-evenly;
            flex-wrap: wrap;
        }
        .b {
            flex: 1 0 30%;
            box-sizing: border-box;
            margin: 8px;
            border: 1px solid #999;
        }
    </style>
</head>

<body>
    <div class="a">
        <div class="b">B</div>
        <div class="b">B</div>
        <div class="b">B</div>
        <div class="b">B</div>
        <div class="b">B</div>
        <div class="b">B</div>
        <div class="b">B</div>
        <div class="b">B</div>
        <div class="b">B</div>
    </div>
</body>

</html>

二、给定一个以数字组成的数组,实现输出id为数字,并且从小到大排序的name(请使用es6语法)
JavaScript
// 调用示例
const source = [
    { id: 4, name: 'test1' },
    { id: {}, name: 'ssdf' },
    "test",
    { id: () => {}, name: 'sf' },
    { id: '6', name: 'test3' },
    { id: 6, name: 'test4' },
    { id: 7, name: 'test7' },
    { id: 2, name: 'test2' },
    { name: 'sf' },
    {},
]

function filterSort() {
    // 写下你的代码    
}

filterSort(source)
// 输出结果如下
['test2', 'test1', 'test4', 'test7']
        第二个面试题是要求将数组过滤一遍后进行排序,这是面试官在看我们对于数组的掌握程度,这个题涉及到了一些数组的高阶函数和常用API,如果对于这些数组常用API还不清除的话,可以去看我这篇文章,里面基本将我们常用的一些数组相关方法总结清楚了。
JS中数组的相关方法整(想要了解数组,看这一篇就足够了)_io_123io_123的博客-CSDN博客JS数组遍历数组、数组常见的API、数组常用的高阶函数

JS中数组的相关方法整理(想要了解数组,看这一篇就足够了)_io_123io_123的博客-CSDN博客JS数组遍历数组、数组常见的API、数组常用的高阶函数https://blog.csdn.net/io_123io_123/article/details/122796706?spm=1001.2014.3001.5501

const source = [
    { id: 4, name: 'test1' },
    { id: {}, name: 'ssdf' },
    "test",
    { id: () => {}, name: 'sf' },
    { id: '6', name: 'test3' },
    { id: 6, name: 'test4' },
    { id: 7, name: 'test7' },
    { id: 2, name: 'test2' },
    { name: 'sf' },
    {},
]
function filterSort(arr) {
    var list = arr.filter(value => {
        return (typeof value.id) == (typeof 1)
    })
    list.sort(function(a, b) {
        return a.id - b.id;
    })
    var lists = []
    list.forEach(value => {
        lists.push(value.name)
    })
    console.log(lists)
}
filterSort(source)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值