str[i] = "x"
Так можно только читать.function reverse(str) {
var i, len = str.length, result = "";
for (i = len - 1; i >= 0; i--) result += str[i];
return result;
}
const getVal = option =>
option.value;
// или
// option.getAttribute('value');
// option.attributes.value.value;
const addText = (option, text) =>
option.text += text;
// или
// option.textContent = option.textContent.concat(text);
// option.innerText = `${option.innerText}${text}`;
// option.append(text);
// option.insertAdjacentText('beforeend', text);
// option.appendChild(document.createTextNode(text));
// option.insertBefore(new Text(text), null);
const addValToText = option => addText(option, getVal(option));
Array.prototype.forEach.call(select, addValToText);
// или
select.querySelectorAll('option').forEach(addValToText);
// или
for (const n of select) {
addValToText(n);
}
// или
for (let i = 0; i < select.options.length; i++) {
addValToText(select.options.item(i));
}
// или
(function add(i, n = select.children[i]) {
if (n) {
addValToText(n);
add(i + 1);
}
})(0);
// или
const add = n => n && (addValToText(n), add(n.nextElementSibling));
add(select.firstElementChild);
4.5.1. The a element
Content model:
Transparent, but there must be no interactive content or a element descendants.
Interactive content is content that is specifically intended for user interaction.
a (if the href attribute is present), audio (if the controls attribute is present), button, details embed, iframe, img (if the usemap attribute is present), input (if the type attribute is not in the Hidden state), label, select, textarea, video (if the controls attribute is present).
The tabindex attribute can also make any element into interactive content.
indexOf()
this.children
, а хочется.[]
и его метод indexOf
call()
(подробнее)indexOf
в качестве this
(где искать) — this.children
,event.target
event.target
среди this.children
-1
, если не нашлось. const langTests = {
'en': textEn,
'ru': textRu,
};
const getText = (lang) => {
const tests = langTests[lang];
return tests[Math.floor(Math.random() * tests.length)];
}
let language = 'en';
getText(language) // 'test2'
gl_FragColor = vec4(color, 0.4 * start);
gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
array.reduce((accumulator, value, index) => {
if (!(accumulator[index % 2] instanceof Array)) {
accumulator[index % 2] = [];
}
accumulator[index % 2].push(value);
return accumulator;
}, []);
array.reduce((accumulator, value, index) => {
accumulator[index % 2].push(value);
return accumulator;
}, [[], []]);
array.reduce((accumulator, value, index) => (accumulator[index % 2].push(value), accumulator), [[], []]);
array.reduce((a, v, i) => (a[i % 2].push(v), a), [[], []]);
const countOff = (array, count) => array.reduce((accumulator, value, index) => {
accumulator[index % count].push(value);
return accumulator;
}, Array.from({ length: count }, () => []));
countOff([1, 2, 3, 4, 5, 6], 2); // [[1, 3, 5], [2, 4, 6]]
countOff([1, 2, 3, 4, 5, 6], 3); // [[1, 4], [2, 5], [3, 6]]
const countUniqueChars = str =>
new Set(str).size;
const countUniqueChars = str => [...str]
.reduce((acc, n) => (acc.includes(n) || acc.push(n), acc), [])
.length;
const countUniqueChars = str => Array
.from(str)
.reduce((acc, n, i, a) => acc + (i === a.indexOf(n)), 0);
const countUniqueChars = str => Object
.keys(Object.fromEntries([].map.call(str, n => [ n, 1 ])))
.length;
const countUniqueChars = str => str
.split('')
.sort()
.filter((n, i, a) => n !== a[i - 1])
.length;
const countUniqueChars = str =>
(str && str.match(/(.)(?!.*\1)/g)).length;