JavaScript 面试备忘单 - 第 1 部分
来源:dev.to
2024-12-26 13:36:34
0浏览
收藏
文章不知道大家是否熟悉?今天我将给大家介绍《JavaScript 面试备忘单 - 第 1 部分》,这篇文章主要会讲到等等知识点,如果你在看完本篇文章后,有更好的建议或者发现哪里有问题,希望大家都能积极评论指出,谢谢!希望我们能一起加油进步!
数组运算
// initialize const arr = []; const arr = new array(size).fill(0); // [0,0,0,0,0] const arr = array.from({length: n}, (_, i) => i); // [0,1,2,...,n-1] // basic operations arr.push(element); // add to end arr.pop(); // remove from end arr.unshift(element); // add to start arr.shift(); // remove from start // slicing and splicing arr.slice(startidx, endidx); // returns new array, endidx not included arr.splice(startidx, deletecount, ...itemstoadd); // common methods arr.map(x => x * 2); // returns new array arr.filter(x => x > 0); // returns new array arr.reduce((acc, curr) => acc + curr, initialvalue); arr.sort((a, b) => a - b); // ascending arr.reverse(); arr.join(''); // convert to string arr.includes(element); // check existence arr.indexof(element); // first occurrence arr.lastindexof(element); // last occurrence
字符串操作
// creation and access const str = "hello"; str.length; str[0] or str.charat(0); // common methods str.substring(startidx, endidx); // endidx not included str.substr(startidx, length); // deprecated but good to know str.slice(startidx, endidx); // can use negative indices str.split(''); // convert to array str.tolowercase(); str.touppercase(); str.trim(); // remove whitespace str.replace(old, new); str.replaceall(old, new); str.startswith(prefix); str.endswith(suffix); str.includes(substr); str.repeat(count);
地图和设置
// map const map = new map(); map.set(key, value); map.get(key); map.has(key); map.delete(key); map.clear(); map.size; // set const set = new set(); set.add(value); set.has(value); set.delete(value); set.clear(); set.size; // object as hashmap const obj = {}; obj[key] = value; key in obj; // check existence delete obj[key]; object.keys(obj); object.values(obj); object.entries(obj);
类和对象
class node { constructor(val) { this.val = val; this.next = null; } } // quick object creation const obj = { key1: value1, key2: value2 };
通用数据结构
// queue using array const queue = []; queue.push(element); // enqueue queue.shift(); // dequeue // stack using array const stack = []; stack.push(element); stack.pop(); // linkedlist node class listnode { constructor(val = 0, next = null) { this.val = val; this.next = next; } } // binary tree node class treenode { constructor(val = 0, left = null, right = null) { this.val = val; this.left = left; this.right = right; } } // trie node class trienode { constructor() { this.children = new map(); this.isendofword = false; } }
位操作
// common operations n << 1; // multiply by 2 n >> 1; // divide by 2 n & 1; // check if odd n & (n-1); // remove last set bit n & -n; // get last set bit n | (1 << pos); // set bit at position n & ~(1 << pos); // clear bit at position n ^ (1 << pos); // toggle bit at position
常见模式和实用程序
// number operations math.max(...arr); math.min(...arr); math.floor(n); math.ceil(n); math.abs(n); number.max_safe_integer; number.min_safe_integer; infinity; -infinity; // random number math.random(); // [0, 1) math.floor(math.random() * n); // [0, n-1] // character code 'a'.charcodeat(0); // 97 string.fromcharcode(97); // 'a' // check type number.isinteger(n); array.isarray(arr); typeof variable; // parsing parseint(str); parsefloat(str);
常见的面试模式
// Two Pointers let left = 0, right = arr.length - 1; while (left < right) { // process left++; right--; } // Sliding Window let left = 0; for (let right = 0; right < arr.length; right++) { // add arr[right] to window while (/* window condition */) { // remove arr[left] from window left++; } } // Binary Search let left = 0, right = arr.length - 1; while (left <= right) { const mid = Math.floor((left + right) / 2); if (arr[mid] === target) return mid; if (arr[mid] < target) left = mid + 1; else right = mid - 1; }
今天关于《JavaScript 面试备忘单 - 第 1 部分》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!
版本声明
本文转载于:dev.to 如有侵犯,请联系study_golang@163.com删除

- 上一篇
- 如何在电脑上高效使用小红书:全面指南

- 下一篇
- 专业电脑装机服务:打造你的个性化工作站
查看更多
最新文章
-
- 文章 · 前端 | 2分钟前 | 按钮点击效果 active伪类
- HTML按钮点击效果太丑?active伪类轻松搞定!
- 496浏览 收藏
-
- 文章 · 前端 | 5分钟前 | JS事件 event处理
- JS事件机制全解,手把手教你搞定event流程
- 281浏览 收藏
-
- 文章 · 前端 | 6分钟前 |
- html中的h2标签是什么意思?手把手教你用好二级标题
- 336浏览 收藏
-
- 文章 · 前端 | 6分钟前 | html 背景颜色
- html怎么设置背景颜色?超简单背景色修改教程
- 181浏览 收藏
-
- 文章 · 前端 | 8分钟前 | CSS文本溢出 文本溢出处理
- CSS文字溢出显示省略号,超简单教程来啦!
- 446浏览 收藏
-
- 文章 · 前端 | 8分钟前 | html 段落间距
- html如何设置段落间距?超简单的CSS技巧
- 501浏览 收藏
-
- 文章 · 前端 | 11分钟前 | html 音频
- audio标签是啥?HTML音频标签基础入门教程
- 417浏览 收藏
-
- 文章 · 前端 | 14分钟前 |
- HTML+CSS实现手风琴效果,超详细Accordion教程!
- 294浏览 收藏
-
- 文章 · 前端 | 18分钟前 |
- 手把手教你用JSFetchAPI搞定网络请求(附代码实例)
- 312浏览 收藏
-
- 文章 · 前端 | 18分钟前 | CSS 文本缩进
- 手把手教你用CSS设置段落首行缩进(text-indent)
- 329浏览 收藏
-
- 文章 · 前端 | 23分钟前 | CSS 动画效果
- 手把手教学!这样加CSS动画超简单,小白也能学会
- 473浏览 收藏
-
- 文章 · 前端 | 24分钟前 | html input标签
- HTMLinput标签太好用了!各种类型+属性全在这了,快收藏!
- 237浏览 收藏
查看更多
课程推荐
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 508次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 484次学习
查看更多
AI推荐
-
- 茅茅虫AIGC检测
- 茅茅虫AIGC检测,湖南茅茅虫科技有限公司倾力打造,运用NLP技术精准识别AI生成文本,提供论文、专著等学术文本的AIGC检测服务。支持多种格式,生成可视化报告,保障您的学术诚信和内容质量。
- 90次使用
-
- 赛林匹克平台(Challympics)
- 探索赛林匹克平台Challympics,一个聚焦人工智能、算力算法、量子计算等前沿技术的赛事聚合平台。连接产学研用,助力科技创新与产业升级。
- 98次使用
-
- 笔格AIPPT
- SEO 笔格AIPPT是135编辑器推出的AI智能PPT制作平台,依托DeepSeek大模型,实现智能大纲生成、一键PPT生成、AI文字优化、图像生成等功能。免费试用,提升PPT制作效率,适用于商务演示、教育培训等多种场景。
- 100次使用
-
- 稿定PPT
- 告别PPT制作难题!稿定PPT提供海量模板、AI智能生成、在线协作,助您轻松制作专业演示文稿。职场办公、教育学习、企业服务全覆盖,降本增效,释放创意!
- 96次使用
-
- Suno苏诺中文版
- 探索Suno苏诺中文版,一款颠覆传统音乐创作的AI平台。无需专业技能,轻松创作个性化音乐。智能词曲生成、风格迁移、海量音效,释放您的音乐灵感!
- 93次使用
查看更多
相关文章
-
- 优化用户界面体验的秘密武器:CSS开发项目经验大揭秘
- 2023-11-03 501浏览
-
- 使用微信小程序实现图片轮播特效
- 2023-11-21 501浏览
-
- 解析sessionStorage的存储能力与限制
- 2024-01-11 501浏览
-
- 探索冒泡活动对于团队合作的推动力
- 2024-01-13 501浏览
-
- UI设计中为何选择绝对定位的智慧之道
- 2024-02-03 501浏览