固然也能够看个人 github 的 issues 欢迎 star!css
其实,如今已经总结的够多了,你们能够看看:html
可是看过了仍是很容易就忘了,仍是得本身敲一遍好。就总结一些本身有问题的地方吧前端
本身遇到以及整理的一些点:react
const a = {
count:1,
b:{
count: 2,
getCount: function(){
console.log(this.count);
}
}
}
const getb = a.b.getCount
console.log(getb())
console.log(a.b.getCount()) // 这里要注意不要被迷惑了
复制代码
理解的话,首先要明确的是 this 是在函数里面,在函数调用时动态指定的,指向当前函数(方法)的执行栈(上下文)。 能够查看 理解 JavaScript 中函数调用和 thiswebpack
一个字符串只由[](){}
这几种构成,要求写一个函数 isMatch(str)
匹配以下格式 (1)({[())]}
(2)([{({[]})})]
,结果返回 booleangit
分析:要求有两个github
[{(
分别都是在 }])
的前面 后来的代码实现:function updateStr(str, reg) {
let isLoop = true;
let result = str;
while (isLoop) {
result = result.replace(reg, (val, str1, str2) => {
val = val.substring(1, val.length - 1);
return val;
});
if (!reg.test(result)) {
isLoop = false;
}
}
return result;
};
function isMatch(str) {
const reg1 = /(\()[\{\}\(\[\]]*(\))/; // 每次匹配一个 (),而后去除
const reg2 = /(\{)[\(\)\{\[\]]*(\})/;// 每次匹配一个 {},而后去除
const reg3 = /(\[)[\[\(\)\{\}]*(\])/;// 每次匹配一个 [],而后去除
const REGS = [reg1, reg2, reg3];
const result = REGS.reduce((total, reg, index) => {
return updateStr(total, reg);
}, str);
return !result;
}
// 测试
let strArray = ['}([(())]){', '{[{([(())])})', '{{[[{([(())])}))'];
let result = strArray.map(val => {
return isMatch(val);
});
console.log(result);
<!--固然在 LeetCode 上也有相似的题目,经过栈的特性来解决的-->
// https://leetcode.com/problems/valid-parentheses/submissions/1
function isMatch(str) {
let map = {
'(': -1,
')': 1,
'[': -2,
']': 2,
'{': -3,
'}': 3
};
let stack = [];
for (let i =0; i < str.length; i++){
if(map[str[i]] < 0){
stack.push(str[i]);
}else{
let last = stack.pop();
if(map[last] + map[str[i]] !==0) return false;
}
}
return stack.length <= 0;
}
复制代码
要求以下web
LazyMan('Tony');
// Hi I am Tony
LazyMan('Tony').sleep(10).eat('lunch');
// Hi I am Tony
// 等待了10秒...
// I am eating lunch
LazyMan('Tony').eat('lunch').sleep(10).eat('dinner');
// Hi I am Tony
// I am eating lunch
// 等待了10秒...
// I am eating diner
LazyMan('Tony').eat('lunch').eat('dinner').sleepFirst(5).sleep(10).eat('junk food');
// Hi I am Tony
// 等待了5秒...
// I am eating lunch
// I am eating dinner
// 等待了10秒...
// I am eating junk food
复制代码
关键点:面试
shift()
调用一个答案算法
要求:
const previous = [{
name: "1",
id: 1,
pid: 0
},
{
name: "2",
id: 2,
pid: 1
},
{
name: "3",
id: 3,
pid: 2
}]
const result = [{
name: "1",
id: 1,
pid: 0,
children:[{
name: "2",
id: 2,
pid: 1
}]
},{
name: "3",
id: 3,
pid: 2
}
]
复制代码
要点:
其实就是树的不一样表现形式
代码实现能够看这里 codesandbox.io/s/nw5xlozk6…
2个正整数字符串的相加,即 '1'+'19' --> '20',注意考虑超长字符串相加
思路:
Number.MAX_VALUE
关键: ETag、CacheControl、Expires 参考 HTTP缓存控制小结
参考
同时,就已经减轻了每台服务器的压力,服务器越多,每一个服务器压力就越小
查看个人博客
平时学习就要多假设一下,为何会这样,若是换成那个(那里)又会怎么样,这二者比较起来有什么不一样!总之要多总结回顾,你会有不同的感觉