[...num+''] = [...`${num}`] = [...num.toString()] = num.toString().split('')
[...`${num}`]
. Просто нагляднее и современнее. if (item.innerText === currentPage) {
item.innerText == currentPage
+item.innerText === currentPage
document.body.insertAdjacentHTML('beforeend', `
<div class="container">
<table>
<thead>
<tr>${keys.map(k => `
<th>${k}</th>`).join('')}
</tr>
</thead>
<tbody></tbody>
</table>
<div class="pagination"></div>
</div>
`);
const tableEl = document.querySelector('.container table');
const paginationEl = document.querySelector('.container .pagination');
paginationEl.addEventListener('click', ({ target: t }) =>
t.matches('a') && showPage(+t.textContent)
);
function showPage(page) {
paginationEl.innerHTML = Array
.from(
{ length: Math.ceil(data.length / rows) },
(_, i) => `<a${-~i === page ? ' class="active"' : ''}>${-~i}</a>`)
.join('');
tableEl.tBodies[0].innerHTML = data
.slice(~-page * rows, page * rows)
.map(n => `
<tr>${keys.map(k => `
<td>${n[k]}</td>`).join('')}
</tr>`)
.join('');
}
showPage(1);
const fs = require('fs');
const path = require('path');
let pathSupplied = './';
let extFilter = 'js';
let extension = (element) => {
let extName = path.extname(element);
return extName === '.' + extFilter;
};
let walk = function (dir) {
const result = [];
fs.readdir(dir, function (err, list) {
list.forEach((item) => {
let itemPath = path.join(dir, item);
fs.stat(itemPath, (e, stats) => {
if (stats.isDirectory()) {
walk(itemPath);
} else {
if(extension(itemPath)){
console.log(itemPath)
result.push(itemPath);
}
}
});
});
});
return result;
}
walk(pathSupplied);
walkAsync = (dir)=>{
return new Promise((resolve)=>{
resolve(walk(dir))
});
}
addToCart = (id: number) => {
let tempProduct: Products[] = [...this.state.products];
const item = this.getItem(id);
if(item === undefined) {
// ... инструкция при возникновении терминального условия, например, ошибка
return;
}
const index = tempProduct.indexOf(item as Products); // строгая типизация для item
// ...
};
getItem = (id: number): Products => {
return this.state.products.find(item => item.id === id);
};
state = {
active: 0,
}
nextSlideHandler = ({ target: { dataset: { step } } }) => {
const len = this.props.images.length;
this.setState(({ active }) => ({
active: (active + len + +step) % len,
}));
}
<button data-step="-1" onClick={this.nextSlideHandler} className="prev">prev</button>
<button data-step="+1" onClick={this.nextSlideHandler} className="next">next</button>
<img src={this.props.images[this.state.active]} />
class Point {
constructor(x, y, ...other) {
if(other.length > 0){
throw 'Only 2 number arguments';
}
if(typeof x !== 'number'){
throw TypeError(`The first argument must be number but have got ${typeof x}`);
}
if(typeof y !== 'number'){
throw TypeError(`The second argument must be number but have got ${typeof y}`);
}
this.x = x;
this.y = y;
}
}
const findMin = obj =>
(obj.children || []).reduce((min, n) => (
n = findMin(n),
min.value < n.value ? min : n
), obj);