const weakMap = new WeakMap();
const array = [{}, {}];
array.forEach(obj => weakMap.set(obj, obj));
const result = array.map(obj => weakMap.get(obj) === obj);
console.log(result);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const team = {
members: ['Alice', 'Bob', 'Charlie'],
[Symbol.iterator]: function*() {
let index = 0;
while(index < this.members.length) {
yield this.members[index++].toUpperCase();
}
}
};
const result = [];
for (const member of team) {
result.push(member);
}
console.log(result.join('-'));
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
var str="My name is John";
var words1=str.split(" ",3);
console.log("words1:",words1);
var words2=str.split(" ",5);
console.log("words2:",words2);
Ответ:
words1:[ 'My', 'name', 'is' ]
words2:[ 'My', 'name', 'is', 'John' ]
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function createCounter() {
let count = 0;
return {
increment: () => ++count,
decrement: () => --count,
getValue: () => count
};
}
const counter1 = createCounter();
const counter2 = createCounter();
counter1.increment();
counter1.increment();
counter2.increment();
console.log(counter1.getValue(), counter2.getValue());
counter1.decrement();
console.log(counter1.getValue(), counter2.getValue());
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM