Created
September 8, 2020 16:53
-
-
Save Carduelis/d2a30c136498ee01e94d84aaf11bc63b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PET_TYPES_MAP = { | |
cat: { | |
male: "Кот", | |
female: "Кошка", | |
freakale: undefined, | |
anyOther: undefined | |
}, | |
rabbit: { | |
male: "Кролик", | |
female: "Крольчиха", | |
}, | |
}; | |
const data = [ | |
{ id: 4, petType: "cat", name: "Сенька", sex: "freakale" }, | |
{ id: 2, petType: "cat", name: "Мешаня", sex: "male" }, | |
{ id: 1, petType: "rabbit", name: "Котя", sex: "female" }, | |
{ id: 3, petType: "cat", name: "Нюся", sex: "female" }, | |
{ id: 5, petType: "human", name: "Лукашик", sex: "male" }, | |
]; | |
const filterByExistedPetType = (item) => { | |
if (PET_TYPES_MAP[item.petType] === undefined) { | |
return false; | |
} | |
return true; | |
}; | |
function mapToLocaleRuString(item) { | |
const petTypeRus = PET_TYPES_MAP[item.petType][item.sex] || "неизвестный пол"; | |
return item.name + " это " + petTypeRus; | |
}; | |
function myStraightFunction(arg1, arg2) { | |
return arg1 + arg2 | |
} | |
const myLambdaFunction = (arg1, arg2) => arg1 + arg2; | |
const result = data | |
.filter(filterByExistedPetType) | |
.map(mapToLocaleRuString) | |
.sort(); | |
const myNumbers = [1,2,3,4,5] | |
myNumbers.map(function(item) { | |
return item * 2 | |
}) | |
myNumbers.map((item) => item * 2); | |
result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment