# 20180728_ARTS_week05

## Algorithm

/**
* https://leetcode.com/problems/longest-palindromic-substring/description/
*
* @param {string} s
* @return {string}
*/

var longestPalindrome = function (s) {

if (s === "") {
return "";
}

let str = Array.from(s);
let res = [-1, -1]; // [maxLen, index]
str.forEach((ch, i) => {
isPalindrom(str, i, i, res);     // a 一阶
isPalindrom(str, i, i + 1, res); // aa 二阶
});

return s.substring(res[1], res[1] + res[0]);
};

function isPalindrom(str, left, right, res) {
let cur = 0;
while (right < str.length && left >= 0 && str[left] === str[right]) {
cur = right - left + 1;
if (cur > res[0]) {
res[1] = left;
res[0] = cur;
}
left--;
right++;
}
}

console.log(longestPalindrome("cbbd"))

## Tip

function Person () {
this.age = 0;
setInterval(function growUp () {
// `this.age` is undefined
// this function has declared its own scope
// different from the Person scope
this.age += 1;
}, 1000)
}

// store the `this` scope in
// a variable to reuse
function Person () {
var that = this;
that.age = 0;
setInterval(function growUp () {
that.age += 1;
}, 1000)
}

// bind the function's `this`
function Person () {
this.age = 0;
setInterval(function growUp () {
this.age += 1;
}.bind(this), 1000)
}

function Person () {
this.age = 0;
setInterval(() => {
this.age += 1;
}, 1000)
}

## Share

2018年7月25日，Mislav Marohnić 发了一条推文：

We’re finally finished removing jQuery from http://GitHub.com frontend. What did we replace it with? No framework whatsoever: • querySelectorAll, • fetch for ajax, • delegated-events for event handling, • polyfills for standard DOM stuff, • CustomElements on the rise.

63 篇文章33 人订阅

0 条评论

## 相关文章

### 基于Html5的Canvas实现的Clocks (钟表)

Canvas是Html5中非常重要的Feature 之一，究竟Canvas的未来会怎么样? 各大巨头有着不同的想法，微软的IE9会全面支持Canvas, Saf...

21060

41230

39700

9320

43760

649100

1.4K30

11710

2.6K90

19970