const chunked = (data, chunkSize) =>
Array.prototype.reduce.call(
data,
(acc, n, i) => (
i = i / chunkSize | 0,
(acc[i] = acc[i] || []).push(n),
acc
),
[]
);
console.log(chunked([...Array(10).keys()], 3));
console.log(chunked('ABCDEFG', 2));
console.log(chunked(document.querySelectorAll('img'), 5));
<yandex-map
ref="map"
...
<button
@click="$refs.map.myMap.balloon.open(координаты, содержимое)"
...
for (let i = 0; i < answer.length - 1; i++)
for (let i = 0; i < words.length; i++)
p.style.color = colors[i]
. yScale.domain(d3.extent(data, (d) => d.amount))
- так вы повторно задаёте интервал значений, беря в качестве границ минимум (был 0, остался 0) и максимум (вместо ранее установленных 100000 стало 50000, поэтому и "линия достигает самого верха графика") своих данных. Начал изучать VueJS. Читал документацию очень много и долго.
new Vue.component
function throttle(f, delay) {
let lastCall = -Infinity;
return function() {
const now = +new Date;
if (now - lastCall > delay) {
lastCall = now;
return f.apply(this, arguments);
}
};
}
date_create(2019-05-16)
$keys = array_keys($arr);
$head = "<tr><th>year</th>".implode("", array_map(function($n) {
return "<th>$n</th>";
}, $keys))."</tr>";
$rows = implode("", array_map(function($key) use($arr) {
return "<tr><td>$key</td>".implode("", array_map(function($n) use($key) {
return "<td>$n[$key]</td>";
}, $arr))."</tr>";
}, array_keys($arr[$keys[0]])));
echo "<table>$head$rows</table>";
Object.entries(props).filter(n => n[1]).map(n => n[0]).join(',')
// или
`${Object.entries(props).reduce((acc, [ k, v ]) => (v && acc.push(k), acc), [])}`
// или
Object.entries(props).map(n => n[1] && n[0]).filter(Boolean).toString()
// или
'' + Object.keys(props).reduce((acc, n) => props[n] ? [ ...acc, n ] : acc, [])
// или
String(Object.keys(props).filter(n => props[n]))
let arrays: [[String]] = [array1, array2]
var combinations: [[String]] = []
let arraysLen: Int = arrays.count
let arrLen: Int = arrays[0].count
let numCombinations: Int = Int(pow(Double(arraysLen), Double(arrLen)))
for i in (0 ..< numCombinations) {
var combination: [String] = []
for j in (0 ..< arrLen) {
let arrIndex: Int = i / Int(pow(Double(arraysLen), Double(j))) % arraysLen
let elIndex: Int = arrLen - j - 1
combination.insert(arrays[arrIndex][elIndex], at: 0)
}
combinations.append(combination)
}
const colors = [ 'red', 'lime', 'yellow', 'aqua', 'brown', 'magenta' ];
$('.item').css('background-color', i => colors[i % colors.length]);
// или
document.querySelectorAll('.item').forEach((n, i) => {
n.style.backgroundColor = colors[i % colors.length];
});
this.sliderPoint.on('click', e => {
this.currentImg = e.target.dataset.id;
this.scrollImages(this.currentImg, this.speed);
});
[...Array(count)].map((n, i) => `<div class="slider-point" data-id="${i}"></div>`).join('')
Array(count).fill('<div class="slider-point"></div>').join('')
this.currentImg = $(e.target).index();
user() {
return new Proxy(this.$store.state.user, {
set: (target, prop, value) => {
this.$store.commit('updateUser', { [prop]: value });
return true;
},
});
},
updateUser(state, payload) {
Object.assign(state.user, payload);
},