const arr = [
{ val: 1, from: 0, to: 25 },
{ val: 2, from: 9, to: 13 },
{ val: 3, from: 14, to: 20 }]
const output = arr
.map(el=>[el.from, el.to])
.flat()
.sort((a,b)=>a-b)
.map((el, index, array)=>array[index+1] && [el, array[index+1]])
.filter(el=>el)
const withSort = WrappedComponent => props => {
return WrappedComponent ? <WrappedComponent {...props} /> : null;
});
export default withSort(Component);
const withSort = (...params) => WrappedComponent => props => {
// params usage
return WrappedComponent ? <WrappedComponent {...props} /> : null;
});
export default withSort(param1, param2)(Component);
git rebase master
, git сделает так:git checkout master
git rebase --continue
процесс продолжится.const newData = Object
.entries(data)
.reduce((acc, [ k, v ]) => (v.length && (acc[k] = v), acc), {});
Object.keys(data).forEach(n => data[n].length || delete data[n]);
Можно использовать Lodash.
const newData = _.pickBy(data, n => n.length);
// или
_.each(data, (v, k) => v.length || delete data[k]);
{
"extends": [
"airbnb",
"prettier",
],
"plugins": [
"prettier"
],
"parser": "babel-eslint"
}
prettier --write
{
"extends": [
"airbnb",
"prettier",
"prettier/react"
],
"plugins": [
"prettier"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"browser": true,
"node": true
},
"rules": {
"no-plusplus": 0,
"no-confusing-arrow": 0,
"no-restricted-syntax": 0,
"guard-for-in": 0,
"class-methods-use-this": 0,
"jsx-a11y/no-static-element-interactions": 0,
"jsx-a11y/anchor-is-valid": 0,
"react/no-danger": 0,
"react/prop-types": 0,
"react/jsx-filename-extension": 0,
"react/jsx-curly-brace-presence": ["error", { "props": "never", "children": "never" }],
"import/no-unresolved": ["error", { "commonjs": true }],
"import/extensions": 0,
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
"import/prefer-default-export": 0,
"prettier/prettier": ["error", {
"singleQuote": true,
"trailingComma": "all"
}]
}
}
"scripts": {
// ваши скрипты
"precommit": "./node_modules/.bin/lint-staged",
},
"lint-staged": {
"**/*.js": [
"./node_modules/.bin/prettier --write",
"./node_modules/.bin/eslint --fix",
"./node_modules/.bin/stylelint './app/**/*.js'", // если используете css in js
"git add"
]
},
import React from 'react';
import { StaticRouter } from 'react-router'
import { Provider } from 'react-redux'
import ReactDOMServer from 'react-dom/server';
import App from './client/components/App.jsx'
ReactDOMServer.renderToString(
<Provider store={ReduxStore}>
<StaticRouter
location={Url}
context={Context}>
<App/>
</StaticRouter>
</Provider>
);
window.__PRELOADED_STATE__ = JSON.stringify(preloadedState || {}).replace(/</g, '\\u003c')
var getDataFromDatabase = function () {
var arr = []
var con = mysql.createConnection(conf.config);
con.connect(function (err) {
if(err) throw err;
con.query("SELECT DID, DName FROM Device")
.on('result', function (data) {
arr.push(data)
})
.on('end', function () {
return callback(null, arr);
})
.on('error', function(err){
return callback (err, null);
});
}
module.exports = {
getDataFromDatabase
}
var fromDB = require(./modulName);
fromDB.getDataFromDatabase(function(err, result){
if(err){
console.log(err);
} else {
console.log(result);
}
})
var getDataFromDatabase = function (callback) {
return new Promise((resolve, reject) => {
var arr = []
var con = mysql.createConnection(conf.config);
con.connect(function (err) {
if (err) throw err;
con.query("SELECT DID, DName FROM Device")
.on('result', function (data) {
arr.push(data)
})
.on('end', function () {
return resolve(arr);
})
.on('error', function (err) {
return reject(err);
})
});
})
}
module.exports = {
getDataFromDatabase
}
var fromDB = require("./modulName");
fromDB.getDataFromDatabase()
.then(result =>{
console.log(result);
},(err)=>{
console.log(err);
})
var getDataFromDatabase = async function (callback) {
return new Promise((resolve, reject) => {
var arr = []
var con = mysql.createConnection(conf.config);
con.connect(function (err) {
if (err) throw err;
con.query("SELECT DID, DName FROM Device")
.on('result', function (data) {
arr.push(data)
})
.on('end', function () {
return callback(null, arr);
})
.on('error', function (err) {
return callback(err, null);
})
});
})
}
module.exports = {
getDataFromDatabase
}
var fromDB = require("./modulName");
var test = await fromDB.getDataFromDatabase();