way2ex / notes Goto Github PK
View Code? Open in Web Editor NEW日常学习中的笔记
日常学习中的笔记
function binaryReverse(s) {
int n= s.length;
if (n <= 1) {
return s
}
var sub1 = s.slice(0, n / 2);
var sub2 = s.slice(n / 2, n);
return binaryRevert(sub2) + binaryRevert(sub1);
}
function forReverse(s) {
var n = s.length;
if (n <= 1) {
return s;
}
var tmp = [];
for (let i = n; i >= 0; i--) {
tmp.push(s[i]);
}
return tmp.join('');
}
function apiReverse(s) {
return a.split('').reverse().join('');
}
回环变位就是一个字符串 s 中的字符在经过循环移动任何位置后得到的另一个字符串,例如: ACTGACG就是 TGACGAC 的变位。
判断两个字符串是否互为回环变位,方法如下:
var a = 'ACTGACG';
var b = 'TGACGAC';
if ( a.length === b.length && a.concat(a).indexOf(b) !== -1 ) {
console.log('两个字符串互为回环变位');
}
第二种方法使用遍历,对每个字符进行左右分隔,然后交换位置,将得到的每个字符串和要比较的字符串对比,如果互为回环变位,则必将命中一个。
var a = 'ACTGACG';
var b = 'TGACGAC';
for (var i = 1; i <= a.length; i++) {
let left = a.slice(0, i);
let right = a.slice(i, a.lenth);
if ( (right + left ) === b ) {
console.log('互为回环变位');
}
}
编辑器另外一个很重要的功能就是代码格式化了,VS Code默认提供常见文件的格式化,如.js
,.html
等。
.vue
文件的格式化支持这里我们添加对.vue
文件的格式化支持。
{
"vetur.format.defaultFormatter": {
"html": "prettier",
"css": "prettier",
"postcss": "prettier",
"scss": "prettier",
"less": "prettier",
"js": "prettier",
"ts": "prettier",
"stylus": "stylus-supremacy"
}
}
这里是设置 Vetur 默认使用的格式化插件 prettier
。 这样对于.vue
文件中的 html
和 javascript
代码都有格式化支持了。
prettier
格式化 .js
文件prettier
在格式化的时候,读取项目的 .eslintrc
的配置,对 js
代码进行格式化。prettier
插件 "prettier.eslintIntegration": true
.vue
文件的格式化prettier
插件对 .vue
文件格式化时,暂不能支持将 eslint
规范应用到 js
代码中。参考资料:
首先确保VS Code 安装了 Vetur 和 Eslint 插件。
然后使用了vue-cli提供的简单webpack模板,这样创建的工程默认没有添加ESLint。
vue init webpack-simple test-vscode
npm i -g eslint@latest
运行
eslint --init
会安装以下依赖
eslint-config-standard@latest
eslint-plugin-import@>=2.2.0
eslint-plugin-node@>=5.2.1
eslint-plugin-promise@>=3.5.0
eslint-plugin-standard@>=3.0.0
同时在项目目录下生成.eslintrc.js
文件。里面只有最基本的内容:
module.exports = {
"extends": "standard"
};
表明我们使用的规则是standard
规范所定义的规则。
2. 然后本地安装最新的eslint
npm i -D eslint@latest
package.json
的 scripts
中添加一行: "lint": "eslint --ext .js,.vue src"
运行:
npm run lint
VS Code会提示我们找不到eslint-config-standard
:
安装它:
npm i -D eslint-config-standard
然后运行
npm run lint
.vue
文件中出错的地方并没有相应的提示。这时Vetur排上用场了。 在VS Code的设置里面添加如下规则:{
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "vue",
"autoFix": true
}
]
}
注意这里添加了 .vue
文件自动修复的规则,如果不添加这个规则,则保存时不会自动修复 .vue
文件。
这样就添加了对.vue
文件的支持。
5. 但是这样会对.vue
文件中的标签报解析错误
这时需要安装eslint-plugin-vue@next
插件。
npm install -D eslint-plugin-vue@next
同时在.eslintrc.js
中添加使用vue插件的扩展。
// .eslintrc.js
module.exports = {
"extends": [
"standard",
"plugin:vue/base"
]
}
这样,就可以对.vue
文件提供实时检查的功能了。
{
"eslint.autoFixOnSave": true
}
通过使用VS Code的插件 Vetur 、ESLint来对Vue工程中的.vue
提供代码检查的功能。
"eslint": "^4.14.0",
"eslint-config-standard": "^11.0.0-beta.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-node": "^5.2.1",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-vue": "^4.0.0-beta.4",
这里 ESLint
和 eslint-plugin-vue
需要是最新的。.eslintrc
的配置
module.exports = {
"extends": [
"standard",
"plugin:vue/base"
]
};
{
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "vue",
"autoFix": true
}
],
"eslint.autoFixOnSave": true
}
参考资料:
Vetur文档
ESLint文档
eslint-plugin-vue
var pression = '12 + 2 ) * 333 - 4 ) * 5 - 6444 ) ) )'.split(' ');
var pressStack = [];
var opStack = [];
for (let i = 0; i < pression.length; i++) {
if ('+-*/'.indexOf(pression[i]) !== -1) {
opStack.push(pression[i]);
} else if ( pression[i].match(/\d+/) ){
pressStack.push(pression[i]);
} else {
let subPression = opStack.pop() + pressStack.pop() + ')';
subPression = '(' + pressStack.pop() + subPression;
pressStack.push(subPression);
}
}
console.log(pressStack.join());
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.