算法
实现栈
class Stack {
private items: any[];
constructor(){
this.items = [];
}
push(...elements:any[]){
this.items = this.items.concat(elements);
}
pop():any{
return this.items.pop();
}
isEmpty():boolean{
return this.items.length === 0;
}
clear(){
this.items = [];
}
size():number{
return this.items.length;
}
print():string{
return this.items.toString();
}
}
队列
class Queue{
private items: any[];
constructor(){
this.items = [];
}
enqueue(...elements:any[]){
this.items = this.items.concat(elements);
}
dequeue(): any{
return this.items.shift();
}
front():any{
return this.items[0];
}
clear(){
this.items = [];
}
isEmpty():boolean{
return this.items.length === 0;
}
size():number{
return this.items.length;
}
print(){
console.log(this.items.toString());
}
}
正则
时分秒:/(([0|1]\d)|(2[0-3])):([0-5]\d):([0-5]\d)/
匹配 16 进制:/#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})/
DOM2 和 DOM3
获取 css 样式值
var divDom = document.querySelector('div');
var computedStyle = window.getComputedStyle(divDom, null);
var width = computedStyle.width
边距描述
// width/height + border + padding + 滚动条
offsetWidth & offsetHeight
// margin + top
offsetLeft & offsetTop
// width/height + padding
clientWidth & clientHeight
// border + margin + top + 滚动条
clientLeft & clientTop
// width/height + padding
scrollWidth & scrollHeight
// 滚动位置
scrollLeft & scrollTop