回复: 9
跳转到指定楼层
上一主题 下一主题
收起左侧

Shopee深圳前端挂经

🔗
匿名用户-DGZLZ  2021-2-12 22:04:32 |倒序浏览

2020(7-9月) 码农类General 硕士 全职@shopee(深圳) - 内推 - 技术电面  | Fail | 在职跳槽

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
都是在牛客在线面试。. 1point3acres.com
一面 代码分析+实现
1. 分析代码 (变量的定义)

  1. (function () {-baidu 1point3acres
  2.   const a = b = 2;.--
  3. })()
  4. console.log("a=", a, " b=", b);. check 1point3acres for more.
复制代码

2. 分析代码 (this,要多了解JS的作用域和执行环境!)

  1. function hello() {
  2.   setTimeout(function() {. 1point3acres
  3.     console.log(this.userName);
  4.   }, 0);.google  и
  5. }
  6. hello.call({ userName: 'Tom' });
复制代码




Follow up: 如果想正确输出'Tom'要怎么修改

3. 分析代码 (隐式类型转换规则)

  1. if ([] == false) console.log(1);
  2. if ({} == false) console.log(2);
  3. if ([]) console.log(3);. .и
  4. if ({}) console.log(4);. From 1point 3acres bbs
  5. if ([1] == [1]) console.log(5);
复制代码


// 凉透了,以下是看了学习资料得出的各种推算过程。。
https://blog.csdn.net/lantian_bupt/article/details/107566580

4. 分析代码 (前端面试必学!学会宏任务和微任务,这类变体都不怕!)

  1. function newPromise = () => Promise.resolve("I have resolved");
  2. function first() {
  3.   newPromise().then(res => {
  4.     console.log(res + " first");
  5.   })
  6.   console.log("first");
  7. }-baidu 1point3acres
  8. async function second() {
  9.   console.log(await newPromise());
  10.   console.log("second");.--
  11. }. From 1point 3acres bbs
  12. first();
  13. second();
复制代码


5. 分析代码 (声明提前). .и

  1. (function() {
  2.   console.log("a=", a);
  3.   console.log("b=", b);
  4.   var a = 2;.
  5.   let b = 3;
  6. })()
复制代码


lz自己加的扩展:函数体提前发生在变量声明提前之前
  1. console.log(a)//?
  2. a();//?
  3. var a =3;
  4. function a(){
  5.    console.log(10);
  6. }
  7. console.log(a);//?
  8. a = 6;
  9. a();//?
复制代码


6. 分析代码

  1. const getKey = (function(a) {
  2.   this.a = a;
  3.   return function (b) {
  4.     return this.a + b;
  5.   }
  6. } (function(a, b, c) {
  7.   return ~~a + ~~b + ~~c;
  8. }.call(1, 2, 2)))

  9. const getArray = function(arr) {
  10.   let res = [];
  11.   for (let i=0; i<arr.length; ++i) {
  12.     res[i] = function() {
  13.       return arr[i];
  14.     }
  15.   }
  16.   return res;
  17. }

  18. const arr = getArray([10, 20, 30, 40, 50, 60, 70, 80, 90]);
  19. console.log(arr[getKey(1)]());
复制代码


// 面试官一开始就先提醒:两个波浪线会将undefined/null等转成数字0,原本是数字的还是保留原来的数字。

7. 实现Lazy Man
写个Man继承自Person,并且支持如下调用:

  1. function Person(name, age) {. check 1point3acres for more.
  2.   this.name = name;
  3.   this.age = age;
  4. }
  5. function Man() {} //这部分需要实现
  6. Man('Tom').sleep(3).eat('dinner');
复制代码


期望输出:
Hello! I'am Tom, 20 years old.
Wait up in 3 seconds.
Eat dinner..google  и

-baidu 1point3acres
面试官都很nice,不会的题会很耐心地引导,最不济也会引导猜一下结果,不过lz基础太差还是凉了。

最后祝各位帅哥美女牛年大吉,offer冲天! 可以的话赏点大米!

评分

参与人数 5大米 +25 收起 理由
瓜瓜tam + 1 赞一个
匿名用户-MWDLU + 18
bryanjhy + 3 给你点个赞!
yuanqijiong + 2 很有用的信息!
sgztql + 1 欢迎分享你知道的情况,会给更多积分奖励!

查看全部评分


上一篇:亚马逊业务分析师面经
下一篇:湾区无人驾驶仿真公司店面挂经--应用直觉
🔗
yhubda 2021-2-13 12:43:19 | 只看该作者
全局:
国内春招前端果然比秋招难好多
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-DGZLZ  2021-2-14 17:52:29 来自APP
yhubda 发表于 2021-02-12 20:43:19
国内春招前端果然比秋招难好多
Lz是秋天面的嗷,只是拖到现在才发的
回复

使用道具 举报

🔗
yhubda 2021-2-15 04:14:00 | 只看该作者
全局:
匿名者 发表于 2021-2-14 17:52
Lz是秋天面的嗷,只是拖到现在才发的

啊这,那看来是shopee难,LZ你看我发的秋招的美团前端面经,每一面都比shopee这个简单。
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-MKSKJ  2021-2-15 07:39:06
本帖最后由 匿名 于 2021-2-15 07:40 编辑 . From 1point 3acres bbs
  1. function Person(name, age) {    this.name = name;
  2.     this.age = age;.--
  3. }. Χ

  4. function Man(name, age) {
  5.     this.queue = [];
  6.     this.timeout = null;. 1point 3 acres
  7.     Person.call(this, name, age);.google  и
  8.     console.log(`Hello, this is ${this.name}, ${this.age} year old`);
  9.     this.sleep = function(time) {
  10.         if(this.timeout) {
  11.             this.queue.push(time);
  12.             return this;
  13.         }
  14.         this.timeout = setTimeout(() => {
  15.             this.timeout = null;
  16.             while(this.queue.length) {
  17.                 const top = this.queue.shift();
  18.                 if(typeof top === 'number') {
  19.                     this.sleep(top);
  20.                     break;-baidu 1point3acres
  21.                 } else if(typeof top === 'function') {
  22.                     top();
  23.                 }
  24.             }. 1point3acres
  25.         }, time * 1000);. Χ
  26.         return this;
  27.     }
  28.     this.eat = function(food) { ..
  29.         const task = console.log.bind(null, `Eat ${food}.`);
  30.         if(this.timeout) {
  31.             this.queue.push(task);
  32.         } else {
  33.             task();
  34.         }
  35.         return this;
  36.     }
  37.     return this;
  38. }

  39. Man('Tom', 20).sleep(3).eat('lamb').sleep(3).eat('chicken');. Waral dи,
复制代码

评分

参与人数 1大米 +3 收起 理由
bryanjhy + 3 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
bluefield 2021-2-15 15:00:34 | 只看该作者
全局:
yhubda 发表于 2021-2-15 04:14
啊这,那看来是shopee难,LZ你看我发的秋招的美团前端面经,每一面都比shopee这个简单。

你是校招是吧?我这个是3~5年的社招可能也是体感更难的原因之一?
回复

使用道具 举报

🔗
bluefield 2021-2-15 15:03:21 | 只看该作者
全局:
匿名者 发表于 2021-2-15 07:39
[mw_shl_code=javascript,true]function Person(name, age) {    this.name = name;
    this.age = age;
...

👍
回复

使用道具 举报

🔗
yhubda 2021-2-15 15:54:30 来自APP | 只看该作者
全局:
bluefield 发表于 2021-02-14 23:00:34
你是校招是吧?我这个是3~5年的社招可能也是体感更难的原因之一?
啊这,我没看仔细,我还以为这也是校招来着
回复

使用道具 举报

🔗
bluefield 2021-3-28 11:25:06 | 只看该作者
全局:
如果允许使用Promise:

  1.     function Person(name, age) {
  2.       this.name = name;.google  и
  3.       this.age = age;
  4.     }
  5.     function Man(name, age) {
  6.       Person.call(this, name, age);
  7.       console.log(`Hello, ${name}! age: ${age}`);

  8.       var next = Promise.resolve();
  9.       return {
  10.         sleep(timeoutSeconds) {
    . check 1point3acres for more.
  11.           next = next.then(() => {
  12.             return new Promise(resolve => {
  13.               setTimeout(resolve, timeoutSeconds * 1000);. Waral dи,
  14.             })
  15.           });
  16.           return this;
  17.         },
  18.         eat(food) {
  19.           next = next.then(() => {
  20.             console.log(`eat ${food}`);
  21.           }). From 1point 3acres bbs
  22.           return this;
  23.         }
  24.       }
  25.     }
  26.     Man('Tom', 20).sleep(3).eat('dinner').sleep(1).eat('apple').sleep(2).eat('junk').sleep(4).eat('abcdefg');
复制代码
回复

使用道具 举报

🔗
bluefield 2021-3-28 11:31:41 | 只看该作者
全局:
如果不让用Promise,不让用async/await:


  1.     function Person(name, age) {.
  2.       this.name = name;
  3.       this.age = age;
  4.     }
  5.     function Man(name, age) {
  6.       Person.call(this, name, age);. check 1point3acres for more.
  7.       console.log(`Hello, ${name}! age: ${age}`);

  8.       var tasks = [];
  9.       var timer = null;
  10.       function next() {
  11.         var task = tasks.shift();
  12.         task && task();
    .
  13.       }
  14.       function add(task) {
  15.         if (timer) {
  16.           tasks.push(task);
    . check 1point3acres for more.
  17.         } else {
  18.           task();
  19.         }
  20.       }
  21.       return {.--
  22.         sleep(timeoutSeconds) {.1point3acres
  23.           add(() => {
  24.             timer = setTimeout(() => {
  25.               timer = null;
  26.               next();
  27.             }, timeoutSeconds * 1000);-baidu 1point3acres
  28.           })
  29.           return this;
  30.         },
  31.         eat(food) {
  32.           add(() => {
  33.             console.log(`eat ${food}`);.1point3acres
  34.             next();
  35.           })
  36.           return this;
  37.         }
  38.       }
  39.     }
  40.     Man('Tom', 20).sleep(3).eat('dinner').eat('cake').sleep(1).eat('apple').eat('pizza').sleep(2).eat('junk').sleep(4).eat('abcdefg');
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表