<?php
declare(strict_types=1);
class Ellipsis
{
private string $char;
private int $count;
/**
* @param string $char
* @param int $count
*/
public function __construct(string $char, int $count)
{
$this->char = $char;
$this->count = $count;
}
/**
* @return string
*/
public function getChar(): string
{
return $this->char;
}
/**
* @return int
*/
public function getCount(): int
{
return $this->count;
}
}
class Ellipsisist
{
private Ellipsis $ellipsis;
/**
* @param Ellipsis $ellipsis
*/
public function __construct(Ellipsis $ellipsis)
{
$this->ellipsis = $ellipsis;
}
/**
* @param string $value
* @return string
*/
public function __invoke(string $value): string
{
return str_pad($value, mb_strlen($value) + $this->ellipsis->getCount(), $this->ellipsis->getChar(), STR_PAD_LEFT);
}
}
class EllipsisistFactory
{
/**
* @param string $char
* @param int $count
* @return Ellipsisist
*/
public static function make(string $char, int $count): Ellipsisist
{
return new Ellipsisist(new Ellipsis($char, $count));
}
}
$arr = ['foo', 'bar', 'baz'];
$ellipsisiatedArr = array_map(
EllipsisistFactory::make('.', 3),
$arr
);
var_dump($ellipsisiatedArr);таймеры как шли так и идут
все данные как были так и есть
И если CryptoJS.SHA512("hello") возвращает корректный хэш строки "hello", то уже i = CryptoJS.SHA512(i) хэширует не строку hello, а инстанс объекта CryptoJS.
Ну и сформулирую вопрос более широко: как мне добиться того, чтобы результат кода исполняемого на C++ был идентичен результату кода исполненного на JS?
const arr = Array.from(
new Set(Array.from(document.querySelectorAll('.shop_name'), n => n.innerText)),
n => ({ name: n })
);const arr = Object.values(Array.prototype.reduce.call(
document.getElementsByClassName('shop_name'),
(acc, { textContent: name }) => (acc[name] ??= { name }, acc),
{}
)); success: function(response){
setTimeout(function() {
document.location.href = `site.ru/test.php?number=${response.number}&name=${response.name}`;
}, 2000);
}success: function(response){
localStorage.setItem('some_key', JSON.stringify(response.data));
setTimeout(function() {
document.location.href = 'site.ru/test.php';
}, 2000);
}let helloHabr = JSON.parse(localStorage.getItem('some_key'));
function shortNumber(val) {
const abs = Math.abs(val);
const prefixIndex = Math.log10(abs) / 3 | 0;
return (
(val < 0 ? '-' : '') +
Math.round(abs / (10 ** (prefixIndex * 3))) +
'KMGTPEZY'.charAt(~-prefixIndex)
);
}shortNumber(99) // '99'
shortNumber(1945) // '2K'
shortNumber(-5839465) // '-6M'
shortNumber(7e10) // '70G'
[].toString() + true + false - null
"" + true // "true"
"" + true + false // "truefalse"
"" + true + false - null // NaN+ не строка, то это не конкатенация и true, false, null будут преобразованы к числам.true + false - null + [].toString()
1 + 0 // 1
1 + 0 - 0 // 1
1 + 0 - 0 + "" // "1"
const elements = document.querySelectorAll('.slider__itm img');
const tag = 'a';elements.forEach(n => {
n.after(document.createElement(tag));
n.nextSibling.append(n);
});for (const n of elements) {
const wrapper = document.createElement(tag);
wrapper.appendChild(n.parentNode.replaceChild(wrapper, n));
}for (let i = 0; i < elements.length; i++) {
const wrapper = document.createElement(tag);
elements[i].replaceWith(wrapper);
wrapper.insertAdjacentElement('afterbegin', elements[i]);
}(function next(i, n = elements.item(i)) {
n && (n.outerHTML = `<${tag}>${n.outerHTML}</${tag}>`, next(-~i));
})(0);