百度前端笔试

1 1 0.7

实在看不懂

!that.isMultiple && values.length > 1 && (values.length = 1);

这句话有什么用。。。。

1.(m-a)(n-b)<=k

let temp = readline().split(' ');
let n, m, k;
n = parseInt(temp[0]);
m = parseInt(temp[1]);
k = parseInt(temp[2]);
if(n > m) {
    [n, m] = [m, n];
}
let sub = m*n - k;
if(parseInt(sub/m) === sub/m) {
    print(sub/m);
}else {
    print(parseInt(sub/m)+1);
}
  1. 能不能完成工作

    let T  = parseInt(readline());
    for(let k = 0;k < T; k++) {
     let n = parseInt(readline());
     let work = [];
     for(let i = 0; i < n; i++) {
         let temp = readline().split(' ');
         work.push({'a':parseInt(temp[0]), 'b':parseInt(temp[1])})
     }
     work.sort((a, b) => a.b - b.b);
    
     let time = 0, judge = true;
     for(let i = 0, len = work.length;i < len; i++) {
         let val = work[i];
         if(val.a + time <= val.b) {
             time += val.a;
         }else {
             judge = false;
         }
     }
     if(judge) {
         print('Yes');
     }else {
         print('No');
     }
    }

3.js操作

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .checkgroup .item{
        height: 42px;
        line-height: 42px;
        padding: 0 10px;
        margin: 10px 0;
        border: 1px solid #c7c7c7;
        border-radius: 6px;
    }
    .checkgroup.radius .item{
        border-radius: 21px;
    }
    .checkgroup .item.selected{
        border: 1px solid #08b292;
        background: #08b292;
        color: #ffffff;
    }
  </style>
</head>
<body>
  <div id="jsCheckGroup">

  </div>
  <script>
    function CheckGroup(renderTo, options, isMultiple) {
        var that = this;
        that.renderTo = renderTo;
        that.options = options;
        that.isMultiple = !!isMultiple;
        that.initHtml();
        that.initEvent();
    }
    CheckGroup.prototype.initHtml = fInitHtml;
    CheckGroup.prototype.initEvent = fInitEvent;
    CheckGroup.prototype.toggleEl = fToggleEl;
    CheckGroup.prototype.isSelected = fIsSelected;
    CheckGroup.prototype.val = fVal;

    function fInitHtml() {
        var that = this;
        // 请补全代码,拼接html字符串
        var sHtml = "";
        if(that.isMultiple) {
          sHtml += "<div class='checkgroup'>"
        }else {
          sHtml+="<div class='checkgroup radius'>"
        }
        for(let i = 0, len = that.options.length; i < len; i++) {
          let item = that.options[i];
          let itemStr = "<div data-val="+item.value+" class='item' onclick='CheckGroup.fToggleEl'>"+item.text+"</div>"
          sHtml += itemStr;
        }
        sHtml+="</div>";
        that.renderTo.innerHTML = sHtml;
        // 请补全代码,获取checkgroup的dom元素引用
        that.el = null;
        that.el = document.getElementsByClassName('checkgroup')[0];
        console.log(that.el.getAttribute('class'));
    }

    function fInitEvent() {
        var that = this;
        that.el && that.el.addEventListener('click', function (event) {
            var item = event.target;
            item.classList.contains('item') && that.toggleEl(item);
        });
    }

    function fToggleEl(item) {
        // 根据当前是单选还是多选,以及当前元素是否选中,高亮/取消���亮指定的选项dom元素
        var that = this;
        let classNames = item.getAttribute('class');
        if (that.isSelected(item)) {
            classNames = classNames.replace('selected', '');
            item.setAttribute('class', classNames);
            // 请补全代码
        } else if (that.isMultiple) {
            classNames += " selected";
            item.setAttribute('class', classNames);
            // 请补全代码
        } else {
           let chose = document.getElementsByClassName('selected')[0];
           if(chose) {
              let classNames = chose.getAttribute('class');
              classNames = classNames.replace('selected', '');
              chose.setAttribute('class', classNames);
           }
           item.setAttribute('class', 'item selected');
            // 请补全代码
        }
    }

    function fIsSelected(item) {
        // 请补全代码,判断item是否选中
        let classNams = item.getAttribute('class');
        if(classNams.includes('selected')) {
          return true;
        }else {
          return false;
        }
    }

    function fVal(values) {
        var that = this;
        if (arguments.length === 0) {
            // 请补全代码,获取高亮的选项元素
            var items = null;
            items = document.getElementsByClassName('selected');
            // 请补全代码,获取高亮的选项元素的data-val
            var result = [];
            for(let i = 0, len = items.length; i < len; i++) {
              let item = items[i];
              result.push(item.getAttribute('data-val'));
            }
            return result;
        }
        !that.isMultiple && values.length > 1 && (values.length = 1);
        // 请补全代码,获取所有的选项元素
        var items = null;
        items = document.getElementsByClassName('item');
        // 请补全代码,在指定元素上加上高亮的class
        for(let i = 0, len = values.length; i < len; i++) {
          for(let j = 0, len2 = items.length; j < len2; j++) {
            if(items[j].getAttribute('data-val') === values[i]) {
              let name = items[j].getAttribute('class') + " selected";
              items[j].setAttribute('class', name);
            }
          }
        }
        var result = [];
        for(let i = 0, len = items.length; i < len; i++) {
          let item = items[i];
          result.push(item.getAttribute('data-val'));
        }
        return result;
    }

    var options = [{text:'选项a', value:'a'}, {text:'选项b', value:'b'}, {text:'选项c', value:'c'}, {text:'选项d', value:'d'}]
    var item = new CheckGroup(document.getElementById('jsCheckGroup'), options, true);
    item.val(['a', 'b', 'c'])
  </script>
</body>
</html>
#前端##笔试题目##秋招#
全部评论
大佬,我就做了0.4,0.8,0.第三题剩20分钟,没看懂什么意思
点赞
送花
回复 分享
发布于 2019-09-17 21:05
最后一题过了吗?
点赞
送花
回复 分享
发布于 2019-09-17 21:07
现代汽车中国前瞻数字研发中心
校招火热招聘中
官网直投
!that.isMultiple && values.length > 1 && (values.length = 1); 作用是,如果挂载的是单选框时把数组截断,保证只会把数组中第一个变为selected
点赞
送花
回复 分享
发布于 2019-09-17 21:08
用来截断数组。。。测试测试着我就明白了。。
点赞
送花
回复 分享
发布于 2019-09-17 21:09
膜拜大佬  最后一题 果断放弃 0.4   0.8    0
点赞
送花
回复 分享
发布于 2019-09-17 21:18

相关推荐

点赞 13 评论
分享
牛客网
牛客企业服务