class Payment {
pub func charge(amount int) void {
if (this.holdAmount < amount && this.initAmount < amount) {
throw new PaymentException('Unavailable charge amount')
}
if (this.status === PaymentStatus:finish) {
throw new PaymentException('Payment already fisnished')
}
this.chargeAmount = amount
this.holdAmount -= amount
this.status = PaymentStatus:finish
}
}
class VeryOpenOne
{
public $property;
}
$voo = new VeryOpenOne();
$name = 'pro' . 'perty';
$voo->$name = 'Пытаясь отрефакторить тот класс, ' .
'ты хрен найдешь, что в этой строчке меняется эта переменная. ' .
'Никакое самое умное IDE не поможет';
const selector = '#point';
.const elem = document.querySelector(selector);
const parent = elem?.parentNode;
const elems = [...parent?.children ?? []];
const index = elems.indexOf(elem);
elems.slice(-~index || elems.length).forEach(n => parent.removeChild(n));
// или
for (
const el = document.querySelector(selector);
el?.nextElementSibling;
el.nextElementSibling.remove()
) ;
// или
document.querySelectorAll(`${selector} ~ *`).forEach(n => n.outerHTML = '');
document.querySelector('.shopWrapper').addEventListener('mouseover', function() {
const color = `#${Math.random().toString(16).slice(2, 8).padEnd(6, 0)}`;
this.style.setProperty('--random-color', color);
});
arr.map(n => {
const ids = Object
.values(n.childrenHash.reduce((acc, m) => ((acc[m.hash] ??= []).push(m.id), acc), {}))
.filter(m => m.length > 1);
return {
...n,
childrenHash: ids.length ? ids : null,
};
})
#itemInner {
counter-reset: bullshit-counter;
}
.row {
counter-increment: bullshit-counter;
}
.row::before {
content: counter(bullshit-counter) "!!!";
}
itemInner.find('.item-num').text(i => i + 1);
const insert = (str, substr, ...indices) => [ 0 ]
.concat(indices)
.filter(n => 0 <= n && n <= str.length)
.sort((a, b) => a - b)
.map((n, i, a) => str.slice(n, a[i + 1]))
.join(substr);
// или
const insert = (str, substr, ...indices) => indices
.sort((a, b) => b - a)
.reduce((acc, n) => (
0 <= n && n <= str.length && acc.splice(n, 0, substr),
acc
), [...str])
.join('');
// или
const insert = (str, substr, ...indices) =>
''.concat(...Array.from(
{ length: -~str.length },
function(_, i) {
return substr.repeat(this[i] ?? 0) + str.charAt(i);
},
indices.reduce((acc, n) => (acc[n] = -~acc[n], acc), {})
));
const insert = (str, substr, ...indices) => indices
.filter(n => 0 <= n && n <= str.length)
.sort((a, b) => a - b)
.reduce((acc, n, i) =>
acc.replace(RegExp(`(?<=^.{${n + i * substr.length}})`), substr)
, str);
// ваш случай
const str = insert(`${number}`, '-', 3, 5, 8, 10);
// вставлять можно больше одного символа
insert('abc', ' --> ', 1, 2) // 'a --> b --> c'
// можно по одному индексу несколько раз делать вставку
insert('abc', '~', 0, 0, 0) // '~~~abc'
// за границы строки вставка не выполняется,
// за исключением позиции сразу же после конца строки
insert('abc', '!', -1, 3, 4) // 'abc!'
function camelize(str) {
return str
.split('-')
.map(function(word, index) {
if (index == 0) {
return word;
} else {
return word[0].toUpperCase() + word.slice(1);
}
})
.join('')
}
let str = prompt('Введите текст через дефис');
alert(camelize(str));
function camelize(str) {
return str
.split('-')
.map((word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1))
.join('')
}
let str = prompt('Введите текст через дефис');
alert(camelize(str));
const upper = (word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1);
function camelize(str) {
return str
.split('-')
.map(upper)
.join('')
}
let str = prompt('Введите текст через дефис');
alert(camelize(str));
const upper = (word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1);
const camelize = str => str.split('-').map(upper).join('');
let str = prompt('Введите текст через дефис');
alert(camelize(str));