class _LazyMan {
constructor(name) {
this.tasks = [];
const task = () => {
console.log(`Hi! This is ${name}`);
this.next();
}
this.tasks.push(task);
setTimeout(() => {
this.next();
}, 0);
}
next() {
const task = this.tasks.shift();
task && task();
}
sleep(time) {
this._sleepWrapper(time, false);
return this;
}
sleepFirst(time) {
this._sleepWrapper(time, true);
return this;
}
_sleepWrapper(time, first) {
const task = () => {
setTimeout(() => {
console.log(`Wake up after ${time}`);
this.next();
}, time * 1000)
}
if (first) {
this.tasks.unshift(task);
} else {
this.tasks.push(task);
}
}
eat(name) {
const task = () => {
console.log(`Eat ${name}`);
this.next();
}
this.tasks.push(task);
return this;
}
}
function LazyMan(name) {
return new _LazyMan(name);
}
let s = "cbbdsdasssdshhdsgfgshigsadifggfstrgusadsfdgsadfdgiyasgigouasohbsdfpapsadmpnsdsas67rgtraddsadsadssaafasf7474safas"
var isPalindrome = function(str:string) {
let left=0,right=str.length-1;
while(right>=left){
if(str.charAt(left)!==str.charAt(right)){
return null;
}
left++;
right--;
}
return str;
}
function longestPalindrome(s: string): string {
let left = 0
let right = 0
let maxlength = 0
let maxString = ''
for (let i =0; i<s.length;i++){
left = i
right = s.length - 1
if(right - left <= maxString.length){
return maxString
}
while (right>left){
if(s.charAt(right) === s.charAt(left)){
let str=isPalindrome(s.slice(left,right+1));
if(str!=null&&str.length>maxString.length){
maxString=str;
break
}
}
right--
}
}
return maxString
};
console.log(longestPalindrome(s))
git cherry-pick
挑选一条commit记录合并
git cherry-pick commit-id