Welcome to js-challenges
> 集锦大厂面试常考的 前端手写题和 leetcode 算法题
### [DOCS](https://sunny-117.github.io/js-challenges/)
## Author
**sunny-117**
- Website: https://sunny-117.github.io/blog/
- Twitter: [@zhiqiangfu6sun](https://twitter.com/zhiqiangfu6sun)
- Github: [@sunny-117](https://github.com/sunny-117)
- personal share: [个人分享](https://jzq422bol5.feishu.cn/docx/doxcnyogD4POabvLHoa1yoEH9W0)
## Project Status
## Star History
# CONTENT
前端手写题集锦 记录大厂**笔试,面试常考**手写题,2026 年前端面试中常见的 leetcode 算法题, 致力打造最全的前端 JavaScript 手写题题库和答案的最优解
> 题目来源:总结了牛客截止到 2026 年 3 月的所有大厂手写题[100%],掘金部分出名的手写题文章,备战前端春招,秋招好友的总结好的题目(github), 就不一一列举链接啦,总之此项目题目来源于社区,答案也由社区讨论后 merge,也完全服务于社区。
谢谢您的 star,您的 star 是我更新的动力
**里面有答案,为了让你们有一个参考,不过非常希望你们能提供自己的思路,指出答案中存在的问题,复杂度优化等等, 期待你们的 contribute, 想来一起维护这个项目,可以联系我,成为 contributor**
最后我把社区的好的答案汇总到一个目录下,答案专栏,方便刷题
主要是让大家讨论出最优解,然后 merge,一起贡献这个项目,有些答案有点问题,所以我给出的答案仅作参考,也欢迎发现的小伙伴提 PR
## Contributing
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/Sunny-117/js-challenges/issues). You can also take a look at the [contributing guide](https://github.com/Sunny-117/js-challenges#%E8%B4%A1%E7%8C%AE%E6%AD%A4%E9%A1%B9%E7%9B%AE).
Thank you to all the people who already contributed to js-challenges!
# 前端 JavaScript 手写题
## JavaScript HOT 100 题
> 中大厂面试,最常考的 100 个题,每一题都非常具有代表性,想要准备面试突击的同学,优先看这些题,祝在座的每一位都能拿到满意的 offer
- [实现 Promise.all](https://github.com/Sunny-117/js-challenges/issues/1)
- [JSON2DOM = react 的 render 函数](https://github.com/Sunny-117/js-challenges/issues/37)
- [树形结构转成列表](https://github.com/Sunny-117/js-challenges/issues/40)
- [列表转成树形结构](https://github.com/Sunny-117/js-challenges/issues/41)
- [Array.prototype.flat](https://github.com/Sunny-117/js-challenges/issues/9)
- [instanceof](https://github.com/Sunny-117/js-challenges/issues/32)
- [call apply bind](https://github.com/Sunny-117/js-challenges/issues/30)
- [Array.prototype.map](https://github.com/Sunny-117/js-challenges/issues/11)
- [正则表达式模版字符串](https://github.com/Sunny-117/js-challenges/issues/48)
- [lodash.get](https://github.com/Sunny-117/js-challenges/issues/20)
- [深拷贝](https://github.com/Sunny-117/js-challenges/issues/58)
- [寄生组合式继承](https://github.com/Sunny-117/js-challenges/issues/59)
- [发布订阅者模式](https://github.com/Sunny-117/js-challenges/issues/60)
- [岛屿数量](https://github.com/Sunny-117/js-challenges/issues/320)
- [实现有并行限制的 Promise 调度器](https://github.com/Sunny-117/js-challenges/issues/149)
- [实现一个 LazyMan ](https://github.com/Sunny-117/js-challenges/issues/382)
## 实现 Promise (hot)
- [完整实现 Promise A+](https://github.com/Sunny-117/js-challenges/issues/8)
- [实现 Promise.all](https://github.com/Sunny-117/js-challenges/issues/1)
- [实现 Promise.prototype.finally](https://github.com/Sunny-117/js-challenges/issues/2)
- [实现 Promise.allSettled](https://github.com/Sunny-117/js-challenges/issues/3)
- [实现 Promise.race](https://github.com/Sunny-117/js-challenges/issues/4)
- [实现 Promise.prototype.catch](https://github.com/Sunny-117/js-challenges/issues/5)
- [Promise.resolve ](https://github.com/Sunny-117/js-challenges/issues/6)
- [Promise.reject](https://github.com/Sunny-117/js-challenges/issues/7)
## Promise 周边场景题(hot)
- [交通灯](https://github.com/Sunny-117/js-challenges/issues/164)
- [封装异步的 fetch,使用 async await 方式来使用](https://github.com/Sunny-117/js-challenges/issues/163)
- [repeat(console.log, 5, 1000)](https://github.com/Sunny-117/js-challenges/issues/162)
- [封装一个工具函数输入一个 promiseA 返回一个 promiseB 如果超过 1s 没返回则抛出异常如果正常则输出正确的值](https://github.com/Sunny-117/js-challenges/issues/161)
- [请求 5s 未完成就终止](https://github.com/Sunny-117/js-challenges/issues/160)
- [实现一个 sleep 函数](https://github.com/Sunny-117/js-challenges/issues/159)
- [js 每隔一秒打印 1,2,3,4,5](https://github.com/Sunny-117/js-challenges/issues/158)
- [使用 setTimeout 实现 setInterval](https://github.com/Sunny-117/js-challenges/issues/156)
- [promise 实现图片异步加载](https://github.com/Sunny-117/js-challenges/issues/155)
- [使用 Promise 封装 AJAX 请求](https://github.com/Sunny-117/js-challenges/issues/154)
- [我们能反过来使用 setinterval 模拟实现 settimeout 吗? ](https://github.com/Sunny-117/js-challenges/issues/157)
- [异步任务:依次发送 3 次网络请求,拿到服务器数据](https://github.com/Sunny-117/js-challenges/issues/172)
- [实现网络请求超时判断,超过三秒视为超时](https://github.com/Sunny-117/js-challenges/issues/171)
- [promise 中断请求](https://github.com/Sunny-117/js-challenges/issues/170)
- [给定一系列的 api,测量上传速度(实现的时候用的 GET 请求)并选择一个加载时间最短的 api](https://github.com/Sunny-117/js-challenges/issues/169)
- [settimeout 系统补偿时间](https://github.com/Sunny-117/js-challenges/issues/168)
- [setTimeout 准时](https://github.com/Sunny-117/js-challenges/issues/167)
- [请求五秒未完成则终止](https://github.com/Sunny-117/js-challenges/issues/166)
- [并发多个请求,返回先得到 response 的。函数输入为 url 数组,输出为第一个返回的 response 的结果](https://github.com/Sunny-117/js-challenges/issues/165)
- [JS 异步数据流,实现并发异步请求,结果顺序输出](https://github.com/Sunny-117/js-challenges/issues/153)
- [Promise 串行](https://github.com/Sunny-117/js-challenges/issues/152)
- [处理高并发, 100 条数据,带宽为 10, 跑满带宽](https://github.com/Sunny-117/js-challenges/issues/151)
- [设计一个简单的任务队列, 要求分别在 1,3,4 秒后打印出 "1", "2", "3";](https://github.com/Sunny-117/js-challenges/issues/150)
- [实现有并行限制的 Promise 调度器](https://github.com/Sunny-117/js-challenges/issues/149)
- [实现 Scheduler](https://github.com/Sunny-117/js-challenges/issues/148)
- [有并发限制的 Promise.all(ts 类型) ](https://github.com/Sunny-117/js-challenges/issues/147)
- [实现 如果上一次的没请求完,之后的就无响应](https://github.com/Sunny-117/js-challenges/issues/146)
- [使用 Promise 实现每隔三秒输出时间](https://github.com/Sunny-117/js-challenges/issues/145)
- [使用 Promise 改写回调地狱](https://github.com/Sunny-117/js-challenges/issues/144)
- [设计一个函数,该函数的参数为可同时发送请求的大小,返回一个函数,该函数的参数为要请求的 url。 实现的效果为,同时发送 n 个请求,当有请求返回后往请求队列里 push 新的请求,并输出刚刚结束的请求的返回值](https://github.com/Sunny-117/js-challenges/issues/143)
- [Promise.retry 超时重新请求,并在重试一定次数依然失败时输出缓存内容](https://github.com/Sunny-117/js-challenges/issues/142)
- [写一个 mySetInterVal(fn, a, b),每次间隔 a,a+b,a+2b 的时间,然后写一个 myClear,停止上面的 mySetInterVal](https://github.com/Sunny-117/js-challenges/issues/141)
## JavaScript 常考手写题
- [产生一个不重复的随机数组](https://github.com/Sunny-117/js-challenges/issues/140)
- [await async 如何实现 ](https://github.com/Sunny-117/js-challenges/issues/280)
- [使用递归完成 1 到 100 的累加 ](https://github.com/Sunny-117/js-challenges/issues/138)
- [打印出 1~10000 以内的对称数](https://github.com/Sunny-117/js-challenges/issues/137)
- [实现一个字符串匹配算法 indexOf](https://github.com/Sunny-117/js-challenges/issues/136)
- [请实现一个模块 math,支持链式调用 math.add(2,4).minus(3).times(2); ](https://github.com/Sunny-117/js-challenges/issues/135)
- [手写用 ES6proxy 如何实现 arr[-1] 的访问(滴滴 2020)](https://github.com/Sunny-117/js-challenges/issues/134)
- [有一堆整数,请把他们分成三份,确保每一份和尽量相等(11,42,23,4,5,6 4 5 6 11 23 42 56 78 90) ](https://github.com/Sunny-117/js-challenges/issues/133)
- [之字形打印矩阵](https://github.com/Sunny-117/js-challenges/issues/132)
- [数组中的最大值](https://github.com/Sunny-117/js-challenges/issues/131)
- [尾递归(斐波那契数列](https://github.com/Sunny-117/js-challenges/issues/130)
- [实现简单路由 ](https://github.com/Sunny-117/js-challenges/issues/129)
- [封装一个 localstorage 的 setItem 和 getItem 方法](https://github.com/Sunny-117/js-challenges/issues/128)
- [1-1000 回文数](https://github.com/Sunny-117/js-challenges/issues/127)
- [随机生成字符串](https://github.com/Sunny-117/js-challenges/issues/126)
- [判断一个字符串是否为驼峰字符串, judge('ByteDance','BD') -> true judge('Bytedance','BD') -> false](https://github.com/Sunny-117/js-challenges/issues/125)
- [压缩字符串](https://github.com/Sunny-117/js-challenges/issues/124)
- [Map 场景题 ](https://github.com/Sunny-117/js-challenges/issues/123)
- [输入 50a6we8y20x 输出 50 个 a,6 个 we,8 个 y,20 个 x](https://github.com/Sunny-117/js-challenges/issues/122)
- [手写 defineProperty](https://github.com/Sunny-117/js-challenges/issues/121)
- [String string 值一样返回 true Object Object 返回 true function function 都是声明的一个新的变量 返回 false](https://github.com/Sunny-117/js-challenges/issues/120)
- [对输入的字符串:去除其中的字符'b';去除相邻的'a'和'c'](https://github.com/Sunny-117/js-challenges/issues/119)
- [用一行代码,将数组中的字符串和字符串对象(new String(123))直接判定出来](https://github.com/Sunny-117/js-challenges/issues/118)
- [before](https://github.com/Sunny-117/js-challenges/issues/117)
- [实现一下 console.log ](https://github.com/Sunny-117/js-challenges/issues/116)
- [实现(5).add(3).minus(2)功能](https://github.com/Sunny-117/js-challenges/issues/115)
- [将十进制数字转为二进制数字字符串](https://github.com/Sunny-117/js-challenges/issues/114)
- [封装 remove child.remove()销毁自身](https://github.com/Sunny-117/js-challenges/issues/113)
- [字符串中字母的出现次数](https://github.com/Sunny-117/js-challenges/issues/112)
- [输出一个等腰三角形](https://github.com/Sunny-117/js-challenges/issues/111)
- [实现一个函数 a,使其奇数次调用时返回 1,偶数次调用时返回 2(不能使用全局变量)](https://github.com/Sunny-117/js-challenges/issues/110)
- [求 最接近的值](https://github.com/Sunny-117/js-challenges/issues/109)
- [不用循环求和](https://github.com/Sunny-117/js-challenges/issues/108)
- [连续赋值操作](https://github.com/Sunny-117/js-challenges/issues/107)
- [输入一串字符串,根据字符串求出每个字母的数量并返回结果对象。(数字为 1 时可省略](https://github.com/Sunny-117/js-challenges/issues/106)
- [创建包含 10 个 1 的数组 多种方法](https://github.com/Sunny-117/js-challenges/issues/105)
- [['zm', 'za', 'b', 'lm', 'ln', 'k'] ](https://github.com/Sunny-117/js-challenges/issues/104)
- [["0->2", "4->5", "7", "13", "15->16"] ](https://github.com/Sunny-117/js-challenges/issues/103)
- [['ab', 'c', 'ab', 'd', 'c'] => ['ab1', 'c1' ,'ab2', 'd', 'c2'] ](https://github.com/Sunny-117/js-challenges/issues/102)
- [移除空属性](https://github.com/Sunny-117/js-challenges/issues/101)
- [判断两个对象是否相等](https://github.com/Sunny-117/js-challenges/issues/100)
- [一个数组,找出每个数组元素右侧第一个比当前数大的数的下标,时间复杂度 O(N)](https://github.com/Sunny-117/js-challenges/issues/98)
- [寻找出现次数最多的三个标签](https://github.com/Sunny-117/js-challenges/issues/97)
- [素数](https://github.com/Sunny-117/js-challenges/issues/96)
- [实现日期格式化函数](https://github.com/Sunny-117/js-challenges/issues/95)
- [实现 jsonp](https://github.com/Sunny-117/js-challenges/issues/94)
- [URL 反转 ](https://github.com/Sunny-117/js-challenges/issues/93)
- [解析 URL Params 为对象](https://github.com/Sunny-117/js-challenges/issues/92)
- [调用计数器(支持重置)](https://github.com/Sunny-117/js-challenges/issues/91)
- [颜色生成](https://github.com/Sunny-117/js-challenges/issues/90)
- [JavaScript 怎么清空数组](https://github.com/Sunny-117/js-challenges/issues/89)
- [判断 A、B 数组的包含关系(值和数量),A 属于 B 返回 1,B 属于 A 返回 2,两者相等返回 0,其他返回-1](https://github.com/Sunny-117/js-challenges/issues/88)
- [对象的合并](https://github.com/Sunny-117/js-challenges/issues/87)
- [实现一个 无限延伸数组](https://github.com/Sunny-117/js-challenges/issues/86))
- [多行字符串转二维数组](https://github.com/Sunny-117/js-challenges/issues/85)
- [请实现一个通用的 Array 解构赋值](https://github.com/Sunny-117/js-challenges/issues/84)
- [数组合并](https://github.com/Sunny-117/js-challenges/issues/83)
- [数组交集,并集,差集](https://github.com/Sunny-117/js-challenges/issues/82)
- [多维数组全排列](https://github.com/Sunny-117/js-challenges/issues/81)
- [判断对象是否存在循环引用](https://github.com/Sunny-117/js-challenges/issues/80)
- [实现函数 solution(arr, k)](https://github.com/Sunny-117/js-challenges/issues/79)
- [逆对象扁平](https://github.com/Sunny-117/js-challenges/issues/78)
- [对象扁平化](https://github.com/Sunny-117/js-challenges/issues/77)
- [实现 执行一次的函数 ](https://github.com/Sunny-117/js-challenges/issues/76)
- [链式调用](https://github.com/Sunny-117/js-challenges/issues/75)
- [偏函数 ](https://github.com/Sunny-117/js-challeng