对设计或页面进行 WCAG 2.1 AA 无障碍审计。触发关键词:“audit accessibility”、 “check a11y”、 “is this accessible?” 或在审查设计时使用。

数组运算
// 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; // divide by 2 n & 1; // check if odd n & (n-1); // remove last set bit n & -n; // get last set bit n | (1 <h2> 常见模式和实用程序 </h2><pre class="brush:php;toolbar:false;">// 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
Java免费学习笔记:立即使用
解锁 Java 大师之旅:从入门到精通的终极指南










