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
// 字符串匹配,"foo foo bar" "aab" return true! | |
//a->b, a<-b | |
//hash[foo] = a | |
//hash[bar] = b | |
//'a b', 'a' | |
function isPatternMatch(_a, b){ |
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
// a > b, b > c, b > a //=> false | |
// a > b, b > c //=> true | |
//can i talk about my thought now? | |
//hao a | |
//assume there's no duplicate name? | |
//every 'a' means the same element |
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
// merge two sorted linked list,lc原题. | |
// 只是又问了两个follow up,一个是去除重复元素merge怎么做,另一个是merge的时候不算重复的数字怎么做 | |
// //initialize | |
// dummyhead | |
// head = dummyhead | |
// pre = null | |
// //move next |
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
// 实现两个函数addorupdate()和recentevents(limit), | |
// 就是类似lru cache,第一个函数是加入或者更新一个事件, | |
// 然后第二个函数返回limit个最近加入或访问的事件。 | |
function DataStructure(){ | |
this.hash = {} | |
this.dummyHead = new Dbll(null) | |
this.dummyTail = new Dbll(null) | |
this.dummyHead.next = this.dummyTail | |
this.dummyTail.pre = this.dummyHead |
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
// 假设类中有一个方法,给定时间范围和最大次数,假设在给定时间范围内,test()被用的次数超过最大次数,那么超过的次数无效,并且返回错误,如果没有超过的话,就可以继续调用. | |
// 例子 | |
// 方法, 范围五秒, 次数三次, | |
// ---------- | |
// 运行: | |
// 方法 | |
// 睡1秒 | |
// 方法 | |
// 睡1秒 | |
// 方法 |
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
var input = { | |
a: { b : { c : 1 }, f : {g : 2}}, | |
c: { d : 2 }, | |
e: null, | |
f: {g: null} //这个应该输出什么 | |
//是NULL还是一个变量啊?不知道啊那个人应该不是用javasscript的我们就当null好了 | |
} | |
var output = {'a.b.c': 1, 'a.f.g': 2, 'c.d': 2, 'e': null, 'f.g': null} | |
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
function A(){ | |
var _private = 0; | |
this.getter = function(){ | |
return _private; | |
} | |
this.setter = function(val){ | |
_private = val; | |
} | |
} |
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
var d = Date.prototype; | |
Object.defineProperty(d, "year", { | |
get: function() {return this.getFullYear() }, | |
set: function(y) { this.setFullYear(y) } | |
}); |
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
// Shape - superclass | |
function Shape() { | |
this.x = 0; | |
this.y = 0; | |
} | |
// superclass method | |
Shape.prototype.move = function(x, y) { | |
this.x += x; | |
this.y += y; |
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
// 实现一个函数 sequence,参数是一个数组,是一系列的异步函数,返回一个新的函数, | |
//这个新的函数在调用的时候,会顺序的执行之前传递给 sequence 的函数数组,前一个函数的返回值作为下一个函数的参数,新函数的参数前面部分会传递给函数数组的第一个函数, | |
//当全部执行完成后,调用 新函数的 callback | |
sequence([add1, add2])(1, function (err, res) { | |
if(err) { | |
console.log(err); | |
return; | |
} | |
console.log(res) // 4 |