// function countProperties(obj) {
// let count = 0;
 
// for (let key in obj) {
// if (obj.hasOwnProperty(key)) {
// count += 1;
// }
// }
 
// return count;
// }
 
// const user = {
// name: 'Alice',
// age: 25,
// city: 'Moscow',
// };
 
// console.log(countProperties(user)); // 3
 
// const empty = {};
// console.log(countProperties(empty)); // 0
 
// const withProto = Object.create({ inherited: true });
// withProto.own = 42;
// console.log(countProperties(withProto)); // 1 (только 'own')
 
// function mergeObjects(obj1, obj2) {
// const result = {};
// for (let key in obj1) {
// if(obj1.hasOwnProperty(key)) {
// result[key] = obj1[key]
// }
// }
 
// for (let key in obj2) {
// if(obj2.hasOwnProperty(key)) {
// result[key] = obj2[key]
// }
// }
 
// return result
// }
 
// const a = { x: 1, y: 2 };
// const b = { y: 3, z: 4 };
 
// console.log(mergeObjects(a, b));
// // { x: 1, y: 3, z: 4 }
 
// console.log(mergeObjects({}, { a: 1, b: 2 }));
// // { a: 1, b: 2 }
 
// console.log(mergeObjects({ a: 1 }, { a: 2, b: 3 }));
// // { a: 2, b: 3 }в
 
 
////////////
 
 
const threeSum = (nums) => {
const sortedNums = nums.sort((a, b) => a - b)
const res = []
for(let i = 0; i < sortedNums.length - 2; i++) {
if(i > 0 && sortedNums[i] === sortedNums[i - 1]) {
continue;
}
if(sortedNums[i] < 0) {
break;
}
let left = i + 1;
let right = sortedNums.length - 1;
while(left < right) {
const sum = sortedNums[i] + sortedNums[left] + sortedNums[right]
if(sum === 0) {
res.push([sortedNums[i], sortedNums[left], sortedNums[right]])
} else if( sum < 0) {
left++
} else {
right--
}
}
}
return res
}
 
console.log(threeSum([-1, 0, 1, 2, -1, -4]))
// [ [-1, -1, 2], [-1, 0, 1] ]
 
console.log(threeSum([0, 0, 0]))
// [ [0, 0, 0] ]
 
console.log(threeSum([1, 2, -2, -1]))
// []
 
console.log(threeSum([]))
// []
Click Run to execute JavaScript.
Code runs in an isolated environment.