Day12

1-var str = “hgDzGHjhcxghvcgxzhjzcgjhxzgcjhgsduyfuys”将字符串中出现次数最多的字母弹框输
  function num (str){
    var a = {};
    var b = str.split("");
    // key为元素 值为个数
  for (let i = 0; i < b.length; i++) {
  if(a[b[i]]){
    a[b[i]]++;
  }else{
  a[b[i]] = 1;
  }
  }
  // 通过比较找出最大的
  var maxLetter = "";
  var levelNum = 0;
  for (const k in a) {
    if(a[k] > levelNum){
    levelNum = a[k];
    maxLetter = k;
  }
  }

  alert(maxLetter + ":" + levelNum);

  return maxLetter;
  }
  var cc = "hgDzGHjhcxghvcgxzhjzcgjhxzgcjhgsduyfuys";
  str = cc.toLocaleLowerCase();
  num(str);
2-举例实现对象的深拷贝
  var obj1 = {
  age:10,
  sex:'男',
  hobbies:['赛车','打游戏','打球'],
  dog:{
    name:'小白',
    weight:10,
    color:'白'
  }
  }

  var obj2 = {}
  // 通过函数,把a中属性复制到b
  function copy(a,b){
  // 先去获取a中的属性
  for(var key in a){
    var item = a[key]
    // 判断item是是不是一个数组
    if(item instanceof Array){
    // 如果是数组,b中要按添加新属性,这个属性也是数组形式
    b[key] = []
    // 遍历数组,把a[key]一个个复制到b[key]中
    copy(item,b[key])
    } else if(item instanceof Object){
    b[key] = {}
    copy(item,b[key])
    } else{
    // 普通数据直接复制
    b[key] = item
    }

    }
    }
  copy(obj1,obj2)
  console.dir(obj1)
  console.dir(obj2)
3-举例实现对象方法的继承
  function Cat(name,age){
    this.name = name
    this.age = age
  }
  Cat.prototype.Catxw=function(){
    console.log("吃东西")
  }

  function Dog(weight,sex){
    this.weight = weight
    this.sex = sex
  }
    Dog.prototype = new Cat("老张",12)
    Dog.prototype.Dogx = function() {
  console.log("打人");
  }

    var C = new Dog(70,"男")
    console.log(C.name)
    console.log(C.age)
    console.log(C.weight)
    console.log(C.sex)
    C.Catxw();
    C.Dogx();
4-写一个左中右布满全屏,其中左右固定宽度 200px,中间部分自适应,要求先加载中间部分,写出结构和样式
  <!doctype html>
  <html lang="en">
  <head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
  *{
    margin: 0;
    padding: 0;
  }
  #contentDiv{
    width: 100%;
    display: flex;
    height: 200px;
  }
  #leftDiv,#rightDiv{
    width: 200px;
    height: 200px;
  }
  #leftDiv{
    background: #16A05D;
  }
  #rightDiv{
    background: #DC5044;
  }
  #centerDiv{
    background: #FFCD41;
    height: 200px;
    flex: 1;
  }
  </style>
  </head>
  <body>
  <div id="contentDiv">
  <div id="leftDiv">左边div</div>
  <div id="centerDiv">中间div</div>
  <div id="rightDiv">右边div</div>
  </div>
  </body>
  </html>

posted @ 2021-02-08 20:19  warisFairy  阅读(29)  评论(0)    收藏  举报