230206 面试记录

127 阅读1分钟

今日上机做题,记录一波。

  1. 假如本地机器无法做加减乘除,需用请求服务端来实现
// 以加法为例,现有远程API的模拟实现 addRemote
const addRemote = async (a, b) => new Promise(resolve => {
  setTimeout(() => resolve(a + b), 1000)
})

// 请实现本地的add方法,调用addRemote,能够最优的实现输入数字的加法。
async function add (...args) {}

// 请用示例验证运行结果:
add(1, 2)
  .then(result => {
    console.log(result) // 3
  })

add(3, 5, 2)
  .then(result => {
    console.log(result) // 10
  })
  1. 根据图片实现一个评论的demo image.png

github已同步相关代码