Your function must use map method
-
Write a function which returns array of usernames.
const users = [ { username: "Yuri Gagarin", lang: "ru", }, { username: "Nil Armstrong", lang: "ENG", }, ]; getUserNames(users); // ['Yuri Gagarin', 'Nil Armstrong']
-
Write a function which returns array of lengths of user names
const users = [ { username: "Yuri Gagarin", lang: "ru", }, { username: "Nil Armstrong", lang: "ENG", }, ]; getUsernameLengths(users); // [12, 13]
- Write a function which parses string integers. If it's not possible to parse, then add null
parseInteger(["1", "2", "34"]); // [1, 2, 34]; parseInteger(["1", "px", "2323"]); // [1, null, 2323];
Your functions must use filter method
-
Write a function which remove users with language equals to 'ru'.
const users = [ { username: "Yuri Gagarin", lang: "ru", }, { username: "Nil Armstrong", lang: "ENG", }, ]; filterUsers(users); // [{ username: "Nil Armstrong, lang: "ENG" }]
- Write a function which filters object by field.
const users = [ { username: "Yuri Gagarin", lang: "ru", isAstronaut: true, }, { username: "Nil Armstrong", lang: "ENG", isAstronaut: true, }, { username: "Elon Musk", isAstronaut: false, }, ]; filterByField(users, "isAstronaut"); // [{ username: "Yuri Gagarin", lang: "ru", isAstronaut: true, }, { username: "Nil Armstrong, lang: "ENG" }]
Your function must use reduce
-
Write a function which calculates average age of users.
const users = [ { username: "Yuri Gagarin", lang: "ru", age: 56, }, { username: "Nil Armstrong", lang: "ENG", age: 54, }, ]; getAverageAge(users); // 55
- *Implement these array methods
- forEach
- filter
- map
- every, once