注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
本帖最后由 bluefield 于 2021-2-12 14:31 编辑
都是在线面,用牛客来写代码。基本都是在考前端基础
1. 找到字符串中的第一个回文子串 (初始下标最小的,尽量长的回文子串)
2. (React / 宏任务) 说出代码的输出
- class C {
- f () {
- this.setState({}, () => console.log(1))
- setTimeout(() => console.log(2), 0);
- }
- }
复制代码
3. (宏任务 / 微任务) 说出代码的输出【这类题目的变形很多,不过只要理解宏任务和微任务就不难!】
- setTimeout(() => console.log(2), 0);
- new Promise((resolve, reject) => {
- console.log(3);
- resolve(1);
- })
- .then(i => {. .и
- console.log(i);
- Promise.resolve().then(() => console.log(4))
- });
- console.log(5);
复制代码
4. (原型链,作用域) 说出代码的输出【要深刻地理解JS的变量查找!】
- function Foo() {. 1point 3 acres
- f = function(){ console.log(1); };
- return this;
- }
- Foo.f = function() { console.log(2); };
- Foo.prototype.f = function(){ console.log(3); };
- . 1point3acres
- f(); // ???. 1point3acres
- var f = function() { console.log(4); };. 1point 3 acres
- function f(){ console.log(5); }
- . 1point3acres.com
- Foo.f(); // ???
- f(); // ???
- Foo().f(); // ???
- f(); // ???
- new (Foo.f)(); // ???.
- (new Foo()).f(); // ???
复制代码 . Waral dи,
5. 实现一个Queue,希望使用方法如下
- new Queue()
- .task(1, 3000) // 任务1,需要等待3秒执行. 1point3acres.com
- .task(2, 2000) // 任务2,需要等待2秒执行. 1point3acres
- .task(3, 2000) // 任务3,需要等待2秒执行. Waral dи,
- .task(4, 1000) // 任务4,需要等待1秒执行. check 1point3acres for more.
- .run();
- // 第3秒输出1 ..
- // 第5秒输出2
- // 第7秒输出3
- // 第8秒输出4
复制代码
有个变体,new Queue(2)时模拟2并行的任务执行者:
- new Queue(2)
- .task(1, 3000) // 任务1,需要等待3秒执行
- .task(2, 2000) // 任务2,需要等待2秒执行
- .task(3, 2000) // 任务3,需要等待2秒执行
- .task(4, 1000) // 任务4,需要等待1秒执行
- .run();
- // 第2秒输出2. check 1point3acres for more.
- // 第3秒输出1
- // 第4秒输出3
- // 第4秒输出4
复制代码
. Χ
类似的变体是懒汉:
- new LazyMan("Jake")
- .eat("potato")
- .wait(2000)
- .say("Hello")
- .wait(1000)
- .eat("tomato);.--
- // 期望输出:
- Hello, I'm Jake!
- eat potato
- wait 2000ms // 这里需要真的等2秒
- Hello
- wait 1000ms // 这里需要真的等1秒
- eat tomato
复制代码
6. script 标签的 defer / async
7. 以下代码如何输出. .и
- const list = [1, 2, 3];
- const square = num => {. ----
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- resolve(num * num);
- }, 1000);.--
- });
- }
- function test() {
- list.forEach(async x => {
- const res = await square(x);-baidu 1point3acres
- console.log(res);
- });
- }. From 1point 3acres bbs
- test()
复制代码
.1point3acresFollow up: 如何修改代码在第一秒输出1,第二秒输出4,第三秒输出9
8. 设计一个柯里化函数(currying ),实现sum(100,200)(300)(400); (将所有入口参数相加 )得到1000-baidu 1point3acres
9. versions 是一个项目的版本号列表,因多人维护,不规则。需要实现一个方法,把 versions 里的至从小到大排序。
举例:输入这样的一个 versions. 1point 3acres
['1.45.0', '1.5', '6', '3.3.3.3.3.3.3'],输出是 ['1.5', '1.45.0', '3.3.3.3.3.3', '6']。请注意 '1.45' 比 '1.5' 大。
. 1point 3 acres
希望能对大家有帮助,祝各位新年offer多多!最后,lz比较缺米,求米!
|