-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Queue { | ||
constructor() { | ||
this.queue = [] | ||
} | ||
enQueue(item) { | ||
this.queue.push(item) | ||
} | ||
deQueue() { | ||
return this.queue.shift() | ||
} | ||
getHeader() { | ||
return this.queue[0] | ||
} | ||
getLength() { | ||
return this.queue.length | ||
} | ||
isEmpty() { | ||
return this.getLength() === 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
class Stack { | ||
constructor() { | ||
this.stack = [] | ||
} | ||
push(item) { | ||
this.stack.push(item) | ||
} | ||
pop() { | ||
this.stack.pop() | ||
} | ||
peek() { | ||
return this.stack[this.getLength() - 1] | ||
} | ||
|
||
getLength() { | ||
return this.stack.length | ||
} | ||
isEmpty() { | ||
return this.getLength() === 0 | ||
} | ||
} | ||
|
||
/** | ||
* 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。 | ||
有效字符串需满足: | ||
左括号必须用相同类型的右括号闭合。 | ||
左括号必须以正确的顺序闭合。 | ||
注意空字符串可被认为是有效字符串。 | ||
*/ | ||
|
||
var isValid = function (s) { | ||
const map = { | ||
'(': -1, | ||
')': 1, | ||
'[': -2, | ||
']': 2, | ||
'{': -3, | ||
'}': 3 | ||
} | ||
const len = s.length | ||
const stack = [] | ||
for (let i = 0; i < len; i++) { | ||
if (map[s[i]] < 0) { | ||
stack.push(s[i]) | ||
} else { | ||
let last = stack.pop() | ||
if(map[last] + map[s[i]] !== 0) return false | ||
} | ||
} | ||
if (stack.length > 0) return false | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// 事件代理 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Person { | ||
constructor(name) { | ||
this.name = name | ||
} | ||
sayName() { | ||
console.log(this.name) | ||
} | ||
} | ||
|
||
class Factory { | ||
static create() { | ||
return new Person('cc') | ||
} | ||
} | ||
|
||
// 工厂模式起到的作用就是替我们隐藏了一堆复杂的处理逻辑,我们只需要调用一个方法或者函数就能实现功能 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// es7 装饰器语法 | ||
|
||
function readonly(target, key, descriptor) { | ||
descriptor.writable = false | ||
return descriptor | ||
} | ||
|
||
class Test { | ||
@readonly | ||
name = 'cc' | ||
} | ||
|
||
let t = new Test() | ||
t.name = 'xxx' | ||
|
||
// 例如react中的 react-redux中的 connect |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Plug { | ||
getName() { | ||
return '港版插头' | ||
} | ||
} | ||
|
||
class Target { | ||
constructor() { | ||
this.plug = new Plug() | ||
} | ||
getName() { | ||
return this.plug.getName() + ' 适配器转二脚插头' | ||
} | ||
} | ||
|
||
let target = new Target() | ||
target.getName() // 港版插头 适配器转二脚插头 | ||
|
||
// 如vue的computed,对传进来的value进行包装转换。 |