axios.post('/login', { body: 'Hello' })
.then(function(res) {
alert(res.data);
});
const login = options => axios.post('/login', options);
const login = function(options) {
return axios.post('/login', options);
}
login(options).then(res => alert(res.data));
login(options).then(function(res) {
alert(res.data);
});
async () => {
try {
const { data } = await login(options);
/* some other logic */
} catch e {
console.log('Server request error:', e);
}
}
const circle_1 = [7, 2, 3, 5, 16, 50, 25, 40],
circle_2 = [2, 5, 10, 30, 25, 3, 10, 25],
circle_3 = [25, 10, 2, 10, 5, 2, 10, 5],
circle_4 = [7, 2, 3, 20, 3, 7, 2, 5],
circle_5 = [2, 20, 1, 7, 25, 1, 25],
circle_6 = [3];
function findSum(value, arrays, i = 0) {
for (let j = 0; j < arrays[i].length; j++) {
const el = arrays[i][j];
if (i < arrays.length - 1) {
const result = findSum(value - el, arrays, i + 1);
if (result !== null) {
return [el, ...result];
}
} else if (el === value) {
return [el];
}
}
return null;
}
console.log('result', findSum(136, [
circle_1,
circle_2,
circle_3,
circle_4,
circle_5,
circle_6
]));
// => result [50, 30, 25, 3, 25, 3]
// в вашем './src/app.js'
import './styles/main.sass';
// в конфиге вебпака все надо упростить
// entry
{
app: './src/app.js',
}
// module.rules
{
test: /\.sass$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
'sass-loader'
]
})
}
// plugins
new ExtractTextPlugin('styles/[name].css')
var fs = require('fs')
, request = require('request');
request.get('http://fs.moviestape.net/video/1c4ed0ac8b7d5b4de6c5d58e2ea31a63/serials/Narcos/s01/Narcos.S01E01.mp4')
.on('error', function(err) {
console.error(err);
})
.on('response', function(res) {
console.log(res.statusCode);
console.log(res.headers['content-type']);
})
.pipe(fs.createWriteStream('Narcos.S01E01.mp4'))
.on('finish', function() {
console.log('OK');
});
(def exists #(.exists (clojure.java.io/as-file %)))
(def process-files
(comp
(map #(do-something %)))
(filter #(exists (:path %))))
(sequence process-files audios)
import { compose, filter, into, map } from 'ramda';
const processFiles = compose(
map(audio => doSomething(audio)),
filter(audio => fs.existsSync(audio.path))
);
into([], processFiles, audios);
filterMap
, которая внутри будет императивной, но при использовании будет выглядеть вполне нормально:function filterMap(filterFn, mapFn) {
return arr => {
const newArr = [];
for (let x of arr) {
if (filterFn(x)) newArr.push(mapFn(x));
}
return newArr;
}
}
const processFiles = filterMap(
audio => fs.existsSync(audio.path),
audio => doSomething(audio)
);
processFiles(audios);