面试.html 2.38 KB
<html>

<head>
</head>
<div style="width:200px;height:100px;background: red">
   <div style="height:50%;margin-right:50%;background: blue">
   </div>
</div>
//子元素margin-top,margin-bottom的百分比是根据父元素的高度
//子元素margin-left,margin-right的百分比是根据父元素的宽度
<body>
   <script>

      let a = Array.from(new Array(10000), (item, index) => {
         return index;
      })
      let b = Array.from(new Array(10000), (item, index) => {
         return index * 2;
      })

      let provice = [{
         key: 1,
         value: '山东',
      }, {
         key: 2,
         value: '河南',
      }, {
         key: 1,
         value: '山西',
      },];
      let city = [{
         key: 1,
         value: '青岛',
      }, {
         key: 2,
         value: '郑州',
      }, {
         key: 2,
         value: '安阳',
      }, {
         key: 3,
         value: '太原',
      },];

      let startTime = new Date().getTime();
      // console.log("去重开始 startTime", startTime)

      //方法:new Set
      // let distinct = function (a, b) {
      //    return Array.from(new Set([...a, ...b]));
      // };

      //方法:object
      // function distinct(a, b) {
      //    let obj = {};
      //    let result = [];
      //    for (let item of [...a, ...b]) {
      //       if (!obj[item]) {
      //          obj[item] = 1;
      //          result.push(item);
      //       }
      //    };
      //    return result
      // };
      //面试题延伸
      // let citys = {};
      // city.forEach((item)=>{
      //    citys[item] = citys[item] || [];
      //    citys[item].push(item.value);
      // })

      // provice.forEach((item)=>{
      //    item.citys = citys[item.key];
      // })

      // let endTime = new Date().getTime();
      // console.log("去重结束 endTime", endTime)
      // console.log("去重用时(毫秒)", endTime - startTime)

      function fn() {
         var i = 0;
         return function fnAdd() {
            console.log(i++);
         }
      }
      var fn1 = new fn();
      fn2 = new fn();

      // fn1();
      // fn1();
      // fn2();


      setTimeout(() => {
         console.log("setTimeout 100")
      }, 100)

      setTimeout(() => {
         console.log("setTimeout 0")
      }, 0)

      for (let i = 0; i < 4; i++) {
         console.log('for',i)
      }





   </script>
</body>

</html>