-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (33 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const animalsCollection = [
{
name: 'elephant',
species: 'asian bush',
age: '2 years old',
weight: '6000 kg', // kg
foods: 'grasses, small plants, bushes, fruit, twigs, tree bark',
habitat: 'savanna'
},
{
name: 'lion',
species: 'african',
age: '3 years old',
weight: '190 kg', // kg
foods: 'beef, micin, mouton, venison',
habitat: 'african savanna'
}
]
// -----------------------------------------------------------------------------
const newAnimalsCollection = animalsCollection.map(animal => {
const newAnimal = Object.assign({}, animal)
newAnimal.age = parseInt(newAnimal.age)
newAnimal.weight = parseInt(newAnimal.weight)
newAnimal.foods = newAnimal.foods.split(', ').map(food => {
return transformToTitleCase(food)
})
newAnimal.name = transformToTitleCase(newAnimal.name)
newAnimal.species = transformToTitleCase(newAnimal.species)
newAnimal.habitat = transformToTitleCase(newAnimal.habitat)
return newAnimal
})
console.log('animalsCollection', animalsCollection)
console.log('newAnimalsCollection', newAnimalsCollection)