Skip to content

Commit

Permalink
docs: init questions
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Dec 3, 2018
1 parent 0b13f10 commit 9f6c3e4
Show file tree
Hide file tree
Showing 14 changed files with 3,175 additions and 1 deletion.
88 changes: 88 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

# Created by https://www.gitignore.io/api/node
# Edit at https://www.gitignore.io/?templates=node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

#DynamoDB Local files
.dynamodb/

# End of https://www.gitignore.io/api/node

dist/
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

> WIP
# 加入我们

> 完成一个或多个面试题,获取免第一轮面试的面试机会。完成的题目越多,质量越高,在面试中的加分更多。完成后的代码可以任意形式发送给 [email protected]
## 中国团队

### 前端工程师
Expand All @@ -30,4 +34,9 @@ LeetCode 中国的前端团队工作内容:

#### 展现你的能力

[WIP]
- [编写复杂的 TypeScript 类型](./typescript_zh.md)
- [用 Webpack 实现 predictable long term cache](./webpack_zh.md)
- [编写工程化的组件](./engineering_zh.md)
- [用 RxJS 处理复杂的异步业务](./rxjs_zh.md)

> 以上几个问题完成一个或多个都有可能获得面试机会,具体情况取决于提交给我们的代码。完成后的代码请发送给 [email protected]
12 changes: 12 additions & 0 deletions engineering_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 编写工程化的业务模块

## 题目描述

不限语言,不限框架,完成一个 `Autocomplete` 组件。

## 代码要求

- 样式不是考察的重点,可以参考 https://ant.design/components/auto-complete-cn/ 来完成样式部分,也可以参考其它组件库的 `Autocomplete`,不需要像素级别还原
- 你认为过于复杂的细节可以不实现,我们考察的是代码组织能力、抽象能力、代码风格等方面
- 单元测试的 coverage 越高越好
- 以 GitHub repo 的形式存放你的代码,`CI/CD` 越自动越好。比如 push 之后的 `lint``test``codestyle` 检查,`git push tags` 之后的自动发布到 `npm`
3 changes: 3 additions & 0 deletions rxjs_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# RxJS 题

[WIP]
120 changes: 120 additions & 0 deletions typescript_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# TypeScript 题

## 问题定义

假设有一个叫 `EffectModule` 的类

```ts
class EffectModule {}
```

这个对象上的方法**只可能**有两种类型签名:

```ts
interface Action<T> {
payload?: T
type: string
}

asyncMethod<T, U>(input: Promise<T>): Promise<Action<U>>

syncMethod<T, U>(action: Action<T>): Action<U>
```

这个对象上还可能有一些任意的**非函数属性**

```ts
interface Action<T> {
payload?: T;
type: string;
}

class EffectModule {
count = 1;
message = "hello!";

delay(input: Promise<number>) {
return input.then(i => ({
payload: `hello ${i}!`,
type: 'delay'
});
}

setMessage(action: Action<Date>) {
return {
payload: action.payload!.getMilliseconds(),
type: "set-message"
};
}
}
```
现在有一个叫 `connect` 的函数,它接受 EffectModule 实例,将它变成另一个一个对象,这个对象上只有**EffectModule 的同名方法**,但是方法的类型签名被改变了:
```ts
asyncMethod<T, U>(input: Promise<T>): Promise<Action<U>> 变成了
asyncMethod<T, U>(input: T): Action<U>
```
```ts
syncMethod<T, U>(action: Action<T>): Action<U> 变成了
syncMethod<T, U>(action: T): Action<U>
```
例子:
EffectModule 定义如下:
```ts
interface Action<T> {
payload?: T;
type: string;
}

class EffectModule {
count = 1;
message = "hello!";

delay(input: Promise<number>) {
return input.then(i => ({
payload: `hello ${i}!`,
type: 'delay'
});
}

setMessage(action: Action<Date>) {
return {
payload: action.payload!.getMilliseconds(),
type: "set-message"
};
}
}
```
connect 之后:
```ts
type Connected = {
delay(input: number): Action<string>
setMessage(action: Date): Action<number>
}
const effectModule = new EffectModule()
const connected: Connected = connect(effectModule)
```
## 要求
在 [题目链接](https://codesandbox.io/s/o4wwpzyzkq) 里面的 `index.ts` 文件中,有一个 `type Connect = (module: EffectModule) => any`,将 `any` 替换成题目的解答,让编译能够顺利通过,并且 `index.ts``connected` 的类型与:
```typescript
type Connected = {
delay(input: number): Action<string>;
setMessage(action: Date): Action<number>;
}
```
**完全匹配**。
13 changes: 13 additions & 0 deletions webpack-zh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# predictable long term cache 代码模板

## 项目依赖

- NodeJS >= 10
- yarn >= 1.12

## 解题步骤

- 使用 `yarn` 安装依赖
- 修改 [webpack.config.js](./webpack.config.js) 到符合题目要求
- 使用 `yarn build` 查看 build 结果
- 修改 `src` 目录下的任意一个文件后再次运行 `yarn build` 查看 `output hash` 是否满足题目要求
19 changes: 19 additions & 0 deletions webpack-zh/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "webpack-zh",
"version": "1.0.0",
"description": "predictable long term cache problem",
"main": "index.js",
"author": "[email protected]",
"license": "MIT",
"private": true,
"devDependencies": {
"webpack": "^4.26.1",
"webpack-cli": "^3.1.2"
},
"scripts": {
"build": "webpack"
},
"dependencies": {
"lodash": "^4.17.11"
}
}
6 changes: 6 additions & 0 deletions webpack-zh/src/common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { sample as lodashSample } from 'lodash'

export function sample(arr) {
console.log('common!!!')
return lodashSample(arr)
}
5 changes: 5 additions & 0 deletions webpack-zh/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as Module1 from './module-1'
import * as Module2 from './module-2'

Module1.logger(['hello', 'world'])
Module2.logData(new Date)
7 changes: 7 additions & 0 deletions webpack-zh/src/module-1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sample } from '../common'

export function logger(msgs) {
console.log('module1')
const msg = sample(msgs)
console.info(msg)
}
6 changes: 6 additions & 0 deletions webpack-zh/src/module-2/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { shuffle, keys } from 'lodash'
import { sample } from '../common'

export function logData(data) {
return sample(shuffle(keys(data)))
}
17 changes: 17 additions & 0 deletions webpack-zh/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @type {import('webpack').Configuration}
*/
module.exports = {
entry: './src/index.js',

mode: 'production',

output: {
filename: '[name].[chunkhash:8].js',
},

optimization: {
runtimeChunk: true,
splitChunks: {},
},
}
Loading

0 comments on commit 9f6c3e4

Please sign in to comment.