js 去重(plus版)

      const getRes = (arr, obj = {}) => {
        return arr.filter((item, index, arr) => {
          let judgeRule
          if (Object.prototype.toString.call(item) === "[object Object]") {
            judgeRule = "object" + Object.entries(item)
          } else judgeRule = typeof item + item
          return obj.hasOwnProperty(judgeRule) ? false : (obj[judgeRule] = true)
        })
      }
      console.log(
        [
          { a: 1 },
          {},
          { a: 1 },
          { a: 1, b: [] },
          [1, 2],
          [1, 2],
          "123",
          123,
          null,
          null,
          NaN,
          undefined,
        ],
        getRes([
          { a: 1 },
          {},
          { a: 1 },
          { a: 1, b: [] },
          [1, 2],
          [1, 2],
          "123",
          123,
          null,
          null,
          NaN,
          undefined,
        ])
      )

全部评论
求 两个日期间的有效日期,https://www.javascriptc.com/interview-tips/zh_cn/javascript/between-two-dates/
点赞
送花
回复 分享
发布于 2022-09-13 21:07 江苏
微众
点赞
送花
回复 分享
发布于 2022-09-14 19:18 江苏
元戎启行
校招火热招聘中
官网直投
小米 1 14; 2 664
点赞
送花
回复 分享
发布于 2022-09-14 19:25 江苏
奇安信: 1. 商场A 满三件六折,商场B 买二送一(送最便宜的),每件都必须买,求最少花费。如[[1,8,2], [4,3,5]] 输出 6 2. 蚂蚁找食物,从原点出发 找到所有食物的最小花费。80%超时了,类似蜜蜂采蜜 function distance (a,b) {     const [a1, a2] = a.split(',&(30872)#39;).map(Number), [b1,b2] = b.split(',&(30872)#39;).map(Number)     return Math.abs(a1-b1) + Math.abs(a2-b2) } function getTotalDistance (list, res=0) {     const todoList = ['0,0&(31488)#39;].concat(list)     for(let i=1; i<todoList.length; i++) {         res += distance(todoList[i-1], todoList[i])     }     return res } function getMinLen ( points, res=Infinity) {     // write code here     const len = points.length     const dfs = (stack) => {         if(stack.length === len) {             res = Math.min(res, getTotalDistance(stack))             return         }         for(let i=0; i<len; i++) {             const cur = points[i].join(',&(30872)#39;)             if(stack.includes(cur)) continue             stack.push(cur)             dfs(stack)             stack.pop()         }     }     dfs([])          return res }
点赞
送花
回复 分享
发布于 2022-09-15 20:55 江苏

相关推荐

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