/** * Implement the sumPromises function, which takes * promises as arguments and returns the sum * of their results. * * The function can accept any number of arguments. * Any promise APIs can be used. */ // Usage example const promise1 = Promise.resolve(1); const promise2 = Promise.resolve(2); sumPromises(promise1, promise2).then(console.log); // 3
Frontend
// Implement a groupBy method that extends the standard array methods. // The method should return a grouped version of the array — an object, // where the keys are the keys of the array from the results of calling the passed function fn(arr[i]), // and the values are arrays containing all the elements of the original array with this key. // code here // Example 1 const array1 = [ { id: 1 }, { id: 1 }, { id: 2 } ]; const fn = (item) => item.id; console.log(array1.groupBy(fn)); // { // 1: [{ id: 1 }, { id: 1 }], // 2: [{ id: 2 }] // } // Example 2 const array2 = [1, 2, 3]; console.log(array2.groupBy(String)); // { // "1": [1], // "2": [2], // "3": [3] // } // Example 3 const array3 = [1.3, 0.5, 1.4]; console.log(array3.groupBy(Math.round)); // { // 1: [0.5, 1.4], // 2: [1.3] // }
** * Implement a runOnce wrapper function that takes * a function and returns a new function. The new function * can only be called once, all subsequent * calls return undefined. * * The wrapped function can accept arguments * and return a result. */ function runOnce(fn) { // your code } const logHello = (name) => { console.log(`hello, ${name}!`) }; const logHelloOnce = runOnce(logHello); console.clear(); logHelloOnce('Oleg'); // 'hello, Oleg!' logHelloOnce('Olga'); // undefined","locale":"kk"}]},{
/* * Write a function that takes a URL as input, * performs a GET request to this URL, * and returns the data (json). * Use fetch to get the data. * Only Promise API can be used. * If an error occurs during the request, try 5 more times. * If data cannot be obtained after all attempts, return the error "The specified URL is inaccessible". */ function get(url) { // code here } get(url) .then(res => console.log(res)) .catch(err => console.error(err))
// You are given a string consisting of Latin letters, spaces, and punctuation marks. // A string is called a pangram if it contains each of the 26 Latin // letters at least once. Determine if the string is a pangram. const LETTERS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; function isPangram(text) { // your code here } console.log(isPangram('A pangram or holoalphabetic sentence is a sentence using every letter of a given alphabet at least once.')); // -> false console.log(isPangram('Waltz, bad nymph, for quick jigs vex.')); // -> true