Sobes.tech

/* Implement the intersection method that extends the standard Set methods. The method takes another set as input and returns a new set that is the intersection of the original and the passed sets, containing only elements present in both sets. */ // your code const set1 = new Set([1, 2, 3, 4]); const set2 = new Set([3, 4, 5, 6, 7, 8]); console.log(...set1.intersection(set2)) // 3 4 --- Set.prototype.intersection = function (set2) { const result = new Set(); for(const value of this) { if (set2.has(value)) result.add(value); } return result; } const set1 = new Set([1, 2, 3, 4]); const set2 = new Set([3, 4, 5, 6, 7, 8]); console.log(...set1.intersection(set2)) // 3 4

159

/** * Implement the sumPromises function that takes * promises as arguments and returns * the sum of their results. * * The function can accept any number of arguments. * You can use any Promise API. */ // Code here // Example usage const promise1 = Promise.resolve(1); const promise2 = Promise.resolve(2); sumPromises(promise1, promise2).then(console.log); // 3

159

What are the limitations of recursive tree traversal? How does depth-first search (DFS) differ from breadth-first search (BFS)? How can tree traversal be implemented without recursion?

157

How else can you get a numeric value from 'this' (besides Number(this))?

157

Explain what happens to a Promise wrapper if asyncCall mistakenly calls the passed callback multiple times: first with an error, then with data, and then again with an error.

156

/** * Implement the compose function, which takes * a variable number of functions and returns a new function. * The result of each function is passed to the next. */ // Code here const square = (x) => x * x; const times2 = (x) => x * 2; const sum = (a, b) => a + b; console.clear(); console.log(compose(square, times2)(2) === square(times2(2))); console.log(compose(square, times2, sum)(3, 4) === square(times2(sum(3, 4))));

153

Implement a function sumPromises that takes promises as arguments and returns the sum of their results. The function can accept any number of arguments, and any Promise API can be used.

153

How can a pseudo-array arguments be converted into a real array? Name several methods.

152

What other Promise API methods do you know besides Promise.all?

152

Where in a real application could the callLimit function with a reset option be useful?

152

What is the difference between the check 'key in result' and 'result.hasOwnProperty(key)'?

151

Why is the sleep execution time not exactly 1000 and 2000 milliseconds, but slightly more? What affects the delay?

151

Why is Array.prototype.slice.call(arguments) used? How do call and apply work?

148

9. Cheating During a test, Professor Floyd noticed some students exchanging notes. Initially, he wanted to give them all failing grades, but the professor was kind and decided to divide students into two groups: those who cheat and those who get failing grades only first. The professor has recorded all pairs of students exchanging notes. You need to determine if he can divide students into two groups so that any note exchange occurs between a student of one group and a student of the other group. Input format The first line contains two numbers N and M — the number of students and the number of pairs exchanging notes (1 ≤ N ≤ 10^2, 0 ≤ M ≤ N(N-1)/2). Next, M lines contain descriptions of pairs of students: two numbers corresponding to the student numbers exchanging notes (student numbering starts from 1, each pair is listed no more than once). Output format You need to output the answer to Professor Floyd's problem. If it is possible to divide students into two groups, output YES; otherwise, NO.

146

[name] asked: In case of parallel development, did the performers clarify the contracts themselves?

146

Determine whether the string is a 'pangram' — a string containing every letter of the alphabet at least once.

146

Implement the isMonotonic function that takes an array of numbers and determines whether it is monotonic (non-increasing or non-decreasing).

143

Tell about your current workplace and project.

142

Rewrite the strjoin function in ES5 without using the rest operator.

142

Why might the apply method be needed in runOnce?

141
/7