((list) => {
let max = {
total: 0,
first: 0,
last: 0,
};
let tmp = {
total: 0,
first: 0,
last: 0,
};
let op = 0;//是否连续,0不连续,1递增连续,-1递减连续
list.forEach((current, i) => {
if (i === 0) {
tmp.total = current;
max.total = current;
return;
}
const prev = list[i - 1];
if (op === 0) {
if (current > prev) {
op = 1;
} else if (current < prev) {
op = -1;
} else {
op = 0;
}
}
if (op !== 0 && current - prev === op) {
tmp.total += current;
} else {
if (max.total < tmp.total) {
max.total = tmp.total;
max.first = tmp.first;
max.last = tmp.last;
}
op = 0
tmp.first = i;
tmp.total = current;
}
tmp.last = i;
});
if (max.total < tmp.total) {
max = tmp;
}
return [
"和值:" + max.total,
"值:" + list[max.first] + "~" + list[max.last],
"索引:" + max.first + "~" + max.last
].join("\n");
})([1, 2, 3, 4, 3, 2, 5, 6, 7, 8]);
All posts in 前端
主要用于开发环境
npm install -g nodemon
用nodemon代替node命令
nodemon run server
npm init -y
-y 是初始化package.json的时候省略掉输入各种信息的步骤,都使用默认值
npm install module_name –save-dev
–save-dev 自动将依赖的模块加到devDependencies中
–save 自动将依赖的模块加到dependencies中
resistanceRatio:0,禁止边缘反馈
可以用来做代码预览功能,或者XSS
<iframe style="display: none;" src="data:text/html,<script>alert(1)</script>"></iframe> <iframe src="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==">
$httpProvider.interceptors.push(['$q',function ($q) { return { request: function (config) { if(config.url==='/admin.php') { return $q.reject('no auth!'); } return config; }, responseError: function(rejection) { if(rejection==='no auth!') { alert('无权限!!!'); return { data: { errno: -1, error:'无权限' } } } return $q.reject(rejection); } } }]);
.testbox{ position: relative; height:300px; border: 4px solid green; width: 400px; } .flex-rows { display: flex; flex-direction: column; position: absolute; top:0; left:0; right:0; bottom:0; } .flex-rows nav{ background-color: #ccc; } .flex-rows article { background-color: #cdc; height:100%; position: relative; } .flex-rows article > .scrollview { position: absolute; top:0; right:0; bottom:0; left:0; overflow: auto; }
<div class="testbox"> <div class="flex-rows"> <nav> Nav.... height:auto </nav> <article> <div class="scrollview"> <ol> <li>...</li><li>...</li><li>...</li><li>...</li><li>...</li> <li>...</li><li>...</li><li>...</li><li>...</li><li>...</li> <li>...</li><li>...</li><li>...</li><li>...</li><li>...</li> <li>...</li><li>...</li><li>...</li><li>...</li><li>...</li> </ol> </div> </article> </div> </div>
See the Pen flex-box布局上下分栏 by Fan Yanan (@fanyanan) on CodePen.light
- header 头
- footer 尾
- nav 导航
- article 文章
- section 段落
- aside 与内容无关的,比如侧栏
new Date('2016-10-17 10:00:00');
在Safari下会被认为是Invalid Date。
需要按照标准的IOS8601格式,如:new Date('2016-10-17T10:00:00');
或严谨点儿带上时区的new Date('2016-10-17T10:00:00+08:00');