Skip to content

杭州 整数智能 校招 笔试 ​

2023-02-22 16:00

  • 1.左右两边占据屏幕 25% 中间 50% 自适应 flex

  • 2.把 url 中的参数转成对象

ts
let httpUrlStr = 'https://www.whatever.com?name=zhangsan&age=18'

function urlToObj(url) {
  const result = {}
  const urlArray = url.split('?')[1].split('&')

  urlArray.forEach(item => {
    const res = item.split('=')
    const key = res[0]
    const val = res[1]
    result[key] = val
  })

  return result
}

console.log(urlToObj(httpUrlStr))
  • 3.数组去重

  • 4.找出字符串中出现最多次数的字符和次数

ts
const str = 'ababajshbaasdaaaa'
// { char:'a',count:9 }

function computeString(str) {
  const compute = {}

  for (let i = 0; i < str.length; i++) {
    let key = str[i]
    if (compute[key]) {
      compute[key] = compute[key] + 1
    } else {
      compute[key] = 1
    }
  }

  let max
  console.log(Object.values(compute))
  Object.values(compute).forEach(item => {
    if (max) {
      if (max < item) {
        max = item
      }
    } else {
      max = item
    }
  })
  let char
  for (const item in compute) {
    if (compute[item] == max) {
      char = item
    }
  }

  return { char, count: max }
}

console.log(computeString(str))
  • 5.防抖
ts
function debounce(callback, time) {
  let timer = null
  return (...args) => {
    if (timer) {
      clearTimeout(timer)
      timer = null
    }
    timer = setTimeout(() => {
      callback(...args)
    }, time)
  }
}

Released under the MIT License.