拼多多3.30前端笔试

两道选择,3道编程(Markdown编辑器,纯手撕,太难受了)

1.promise输出结果

const getPromise = ()=>{
      return new Promise((resolve,reject)=>{
        console.log('a new promise start')
        reject('error')
        console.log('a new promise end')
      })
    }
    async function run(){
      const promise = getPromise()
      promise.catch(console.log)
      const res = await promise
      console.log(res)
    }
    run()

2.代码执行结果

function modifyPerson(person){
      person.age = 2
      person = {age: 3}
      return person
    }
    const person = {age:1}
    modifyPerson(person)
    console.log(person)

3.找出字符串中连续出现最多的字符和对应的出现个数

const arr = str.match(/(.)\1+/g);
const maxLen = Math.max(...arr.map(s => s.length));
const result = arr.reduce((pre, curr) => {
	if (curr.length === maxLen) {
		pre[curr[0]] = curr.length
	}
	return pre;
}, {});
console.log(result) // {c: 3}

4.可指定超时时间的异步函数重试机制

function asyncFn() {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          if (Math.random() < 0.2) {
            console.log('inner success')
            resolve('success')
          } else {
            console.log('inner failed')
            reject('failed')
          }
        }, 5 * 1000 * Math.random())
      })
    }
    function runWithRetry(fn, retryTimes, timeout) {
      return new Promise((resolve, reject) => {
        const tryFn = () => {
          fn()
            .then((result) => {
              resolve(result);
            })
            .catch((error) => {
              if (retryTimes <= 0 || timeout <= 0) {
                reject(error);
              } else {
                console.log(`Retrying ${retryTimes} more times...`);
                setTimeout(() => {
                  tryFn();
                }, 5 * 1000 * Math.random());

                retryTimes--;
                timeout -= 5 * 1000 * Math.random();
              }
            });
        };

        tryFn();
      });
    }
    runWithRetry(asyncFn, 3, 10 * 1000).then(console.log, console.log)

5.补充css布局代码和Js代码,实现简易的九宫格抽奖功能(这波操作很拼多多

全部评论
收到面试通知了吗
1 回复 分享
发布于 2023-04-02 18:55 广东
【可指定超时时间的异步函数重试机制】这题可以使用 Promise.race 实现
点赞 回复 分享
发布于 2023-05-31 18:09 上海
我以为是让你实现一个markdown编辑器,吓死
点赞 回复 分享
发布于 2023-05-04 23:48 上海
吓人,pdd这么难吗
点赞 回复 分享
发布于 2023-04-01 17:33 辽宁

相关推荐

10-22 15:25
门头沟学院 C++
种花网友小松:求求你别发了,我几乎都快嫉妒得疯了,倒在床上蒙住被子就开始抱着枕头尖叫流泪,嘴里一边喊着卧槽卧槽,一边又忍着,我边发边哭,打字的手都是抖的,后来我的手抖得越来越厉害,从心头涌起的思想、情怀和梦想,这份歆羡和悔恨交织在一起,我的笑还挂在脸上,可是眼泪一下子就掉下来了。求你了别发了,我生活再难再穷我都不会觉得难过,只有你们发这种东西的时候,我的心里像被刀割一样的痛,打着字泪水就忍不住的往下流。
我的求职进度条
点赞 评论 收藏
分享
点赞 评论 收藏
分享
11-29 00:55
门头沟学院
区域赛银,邀请赛金,打算十二月打下Java基础、背点八股、写个外卖后去投福建小厂的寒假实习,简历应该怎么写呢?以及福州/和厦门有推荐的小厂吗?
牛客53210502...:简历一页:把区域银,邀请赛金标粗,其他的奖除非凑一页否则没有必要写。或者多页:每个站一行这样都列出来。项目经历看看牛客其他人是怎么写的,写的不好呢。简历打磨好按部就班没问题的
点赞 评论 收藏
分享
评论
10
56
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务