深信服一面

自我介绍 吧啦吧啦。。。

先来写下这道题。。。
给出由小写字母组成的字符串 S,重复项删除操作会选择两个相邻且相同的字母,并删除它们。
在 S 上反复执行重复项删除操作,直到无法继续删除。 
在完成所有重复项删除操作后返回最终的字符串。答案保证唯一。   
示例:
    输入:"abbaca"
    输出:"ca"
     解释: 例如,在 "abbaca" 中,我们可以删除 "bb" 由于两字母相邻且相同,这是此时唯一可以执行删除操作的重复项。
                之后我们得到字符串 "aaca",其中又只有 "aa" 可以执行重复项删除操作,所以最后的字符串为 "ca"。  
const removeDuplicates = function(s) {
    // code
    let sc = s.slice()
    let stack = [sc[0]] // a
    for(let i=1;i<sc.length;i++) {
        // abbaca
        // 
        if(stack.length && sc[i] === stack[stack.length - 1]) {
            stack.pop()
        } else {
            stack.push(sc[i])
        }
    }
        return stack.join('');
};
实现一个tree函数, 将扁平的数据格式转成树结构 
 **pid代表对应所属的父节点**
let data = [
		    {id: 1, pid: 0, text: 'xxx'},
		    {id: 2, pid: 1, text: 'xxx-2'},
		    {id: 3, pid: 1, text: 'xxx-3'},
		    {id: 4, pid: 2, text: 'xxx-2-4'},
		    {id: 5, pid: 3, text: 'xxx-3-5'},
		    {id: 6, pid: 2, text: 'xxx-2-6'}
		];

		// 期望结果
		/*
		*
		[
		  {
		    "id": 1,
		    "pid": 0,
		    "text": "xxx",
		    "children": [
		      {
		        "id": 2,
		        "pid": 1,
		        "text": "xxx-2",
		        "children": [
		          {
		            "id": 4,
		            "pid": 2,
		            "text": "xxx-2-4"
		          },
		          {
		            "id": 6,
		            "pid": 2,
		            "text": "xxx-2-6"
		          }
		        ]
		      },
		      {
		        "id": 3,
		        "pid": 1,
		        "text": "xxx-3",
		        "children": [
		          {
		            "id": 5,
		            "pid": 3,
		            "text": "xxx-3-5"
		          }
		        ]
		      }
		    ]
		  }
		]
		* */
		function tree (data) {
		    //coding
		  let res = []

		  for(let d of data) {
		    for(let t of data) {
		      if(t.pid === d.id) {
		        d.children ? d.children.push(t) : d.children = [t]
		      }
		    }
		  }
		  for(let d of data) {
		    if(d.pid ===0) {
		      res.push(d)
		    }
		  }
		  return res
		}

http1和2的区别

写出一下console的输出
// (1)、
// function f1 () {
//   return this;
// }
// console.log(f1());  // 输出 window

// (2)、
// var prop = 36;
// var o = {
//   prop: 37,
//   bar: function() {
//     return this.prop;
//   }
// };
// console.log(o.bar()); // 输出 37

// (3)、
// var prop = 36;
// var o = {
//   prop: 37,
//   bar1: function() {
//     function foo1() {
//       return this.prop;
//     }
//     return foo1;
//   },
//   bar2: function() {
//     var foo2  = (() => this.prop);
//     return foo2;
//   }
// };
// console.log(o.bar1()());  // 输出 36
// conso.log(o.bar1().call(o)) // 输出 37
// console.log(o.bar2()());  // 输出 37
// var fn2 = o.bar2;
// console.log(fn2()());  // 输出 36

依旧写输出
console.log(1);
  new Promise((resolve, reject) => {
    console.log(2);
    setTimeout(() => {
      console.log(3);
      Promise.resolve().then(() => {
        console.log(4);
      })
    }, 0);
    resolve();
    reject();
    console.log(5);
  }).then(() => {
    console.log(6);
    Promise.resolve().then(() => {
      console.log(7);
    })
    setTimeout(() => {
      console.log(8);
    }, 0);
  }, () => {
    console.log(10);
  })





#深信服面经##深信服##面试题目#
全部评论
点赞 回复
分享
发布于 2021-11-30 16:55
点赞 回复
分享
发布于 2021-11-30 17:53
滴滴
校招火热招聘中
官网直投
😏
点赞 回复
分享
发布于 2021-11-30 17:53
抖音直播广深都在搭建研发团队,客户端/前后端有海量位置,岗位jd参考https://job.toutiao.com/s/RpdJ5HM,校招还有岗位,内推、详询可以私聊找我哦
点赞 回复
分享
发布于 2021-12-03 09:38

相关推荐

4 14 评论
分享
牛客网
牛客企业服务