Commit ef9620eb authored by Gabriel Dantas's avatar Gabriel Dantas
Browse files

upload project

parents
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
\ No newline at end of file
// ['oi', 'ele', 'ag']
// lista.qualquerMetodo( function ( elementoAtual, indice){
// // ! alguma logica
// })
// ? SOME & EVERY /// => r e t o r n o b o l e a n o /////////////////////
///#region
// const groupHasCentenarian = people.some( person => person.age > 100)
// const groupIsMadeOfCentenarians = people.every( person => person.age > 100)
// console.log('groupHasCentenarian: ' + groupHasCentenarian)
// console.log('groupIsMadeOfCentenarians: ' + groupIsMadeOfCentenarians)
// people.push({id: 'p5', name: 'Enzo', age: 10})
// const groupIsOfAge = people.every( person => person.age >= 18)
// console.log('Amanhã sextou! 🎉🎉 \n')
// if(groupIsOfAge) {
// console.log('Eu levo a vodka! 🍹🍸')
// } else {
// console.log('Eu levo o Tang🍇! 🥤')
// }
///#endregion
// ? FIND & FIND_INDEX => r e t o r n o ú n i c o ///////////////////////////////
// const people = [
// { id: 'p1', name: 'Gabriel', age: 27},
// { id: 'p2', name: 'Elsa', age: 198},
// { id: 'p3', name: 'Alexandria Ocassio-Cortez', age: 31},
// { id: 'p4', name: 'Rita Von Hunty', age: 27},
// ]
// const selectedPerson = people.find( person => person.id === 'p3')
// const selectedIndex = people.findIndex( person => person.id === 'p3')
// const selectedPerson = people.find( person => person.age < 30)
// const selectedIndex = people.findIndex( person => person.age < 30)
// console.log(selectedPerson)
// console.log(selectedIndex)
// ? FOR EACH /// => r e t o r n o i n e x i s t e n t e ///////////////
// !'step 1'
// const array1 = ['🍔','🥓','🥗','🍚']
// array1.forEach( function (item) {
// console.log(item)
// })
// !'step 2'
// const array1 = ['🍔','🥓','🥗','🍚']
// const test = array1.forEach( item => {
// console.log(item)
// })
// console.log(test)
// !'step 3'
// const array1 = ['🍔','🥓','🥗','🍚']
// const anotherArray = []
// array1.forEach( function (item, index, array) {
// console.log('array original: ' + array)
// array.push('oi')
// if(index < 2) {
// anotherArray.push(item)
// }
// })
// console.log(array1)
// console.log('\nanotherArray: ' + anotherArray)
// ? MAP // => r e t o r n a l i s t a c o m m u t a ç ã o ///////////////////////////////
// !'step 1'
// const array2 = ["🍔", "🥓", "🥗", "🍚"];
// const newArray = array2.map(function (item) {
// const newItem = item + "🥤";
// return newItem;
// });
// console.log("newArray: " + newArray);
// !'step 2'
// const array2 = ["🍔", "🥓", "🥗", "🍚"];
// const newArray = array2.map(function (item, index) {
// let newItem = item
// if(index % 2 === 0) {
// newItem += "🥤"
// }
// return newItem;
// });
// console.log("array2: " + array2);
// console.log("\nnewArray: " + newArray);
// !'step 3'
// const pokemons = require('./data/pokemons.json')
// // console.log(pokemons)
// const basicPokemonData = pokemons.map(function (pokemon) {
// const pokemonData = {
// name: pokemon.name,
// abilities: pokemon.abilities.map(function (ability) {
// return ability.ability.name
// })
// }
// return pokemonData;
// });
// console.log(basicPokemonData);
// !'step 4'
// const persons = [ { id: 'p1', name: 'Gabriel', car: 'c1'}]
// const cars = [ { id: 'c1', name: 'Doblo', color: 'red', owner: 'p1'}]
// const peopleWithPossessions = persons.map(function (person) {
// const ownedCar = cars.find( car => car.id === person.car)
// const personWithPossessions = {
// ...person,
// car: {...ownedCar}
// }
// return personWithPossessions;
// });
// console.log(peopleWithPossessions);
// ? FILTER // => r e t o r n a l i s t a r e d u z i d a /////////////////////
// !'step 1'
// const array3 = [ '🥢🍣','🌯','🍢','🍤🥢']
// const filteredArray = array3.filter( function(comida) {
// return comida.includes('🥢')
// })
// console.log(filteredArray)
// !'step 2'
// const array3 = ["🥢🍣", "🌯", "🍢", "🍤🥢"];
// const filteredArray = array3.filter(function (comida, indice) {
// return comida.includes("🥢") && indice < 2;
// });
// console.log(filteredArray);
// !'step 3'
// const pokemons = require("./data/pokemons.json");
// const pokemonsWithLimber = pokemons
// .filter(function (pokemon) {
// return pokemon.abilities.some(function (abil) {
// return abil.ability.name === "intimidate";
// });
// })
// // .map( function(pokemon) { return pokemon.name });
// .map( (pokemon) => pokemon.name );
// console.log(pokemonsWithLimber);
// ? REDUCE // => r e t o r n o " r e d u z i d o " //////////////////////////////////////////
// !'step 1'
// const statements = [
// { type: 'income', value: 100},
// { type: 'outcome', value: 20},
// { type: 'income', value: 150},
// { type: 'outcome', value: 47},
// { type: 'outcome', value: 66},
// ]
// const totalOfValues = statements.reduce( function ( acc, current) {
// return acc = acc + current.value
// }, 0)
// console.log('totalOfValues: ' + totalOfValues)
// const receita = statements.reduce( function(acc, current) {
// if(current.type === 'income') {
// return acc += current.value
// }else {
// return acc -= current.value
// }
// }, 0)
// console.log('receita: ' + receita)
// !'step 2'
// const statements = [
// { type: 'income', value: 100},
// { type: 'outcome', value: 20},
// { type: 'income', value: 150},
// { type: 'outcome', value: 47},
// { type: 'outcome', value: 66},
// ]
// const receita = statements.reduce( function(acc, current) {
// if(current.type === 'income') {
// return acc += current.value
// }else {
// return acc -= current.value
// }
// }, 0)
// console.log('receita: ' + receita)
// function addStatement(statement) {
// if( statement.type === 'outcome' && receita < statement.value) {
// console.log('Não há saldo suficiente')
// } else {
// statements.push(statement)
// }
// }
// const newStatement = { type: 'outcome', value: 1030}
// addStatement(newStatement)
// console.log(statements)
// !'step 3'
const statements = [
{ type: "income", value: 100 },
{ type: "outcome", value: 20 },
{ type: "income", value: 150 },
{ type: "outcome", value: 47 },
{ type: "outcome", value: 66 },
];
const statementTypes = statements.reduce(function (acc, current) {
const typeIsAlreadyIn = acc.some(function (type) {
return type === current.type;
});
if (!typeIsAlreadyIn) {
acc.push(current.type);
}
return acc;
}, []);
console.log("statementTypes:");
console.log(statementTypes);
{
"name": "ditto",
"abilities": [
{
"ability": {
"name": "limber",
"url": "https://pokeapi.co/api/v2/ability/7/"
},
"is_hidden": false,
"slot": 1
},
{
"ability": {
"name": "imposter",
"url": "https://pokeapi.co/api/v2/ability/150/"
},
"is_hidden": true,
"slot": 3
}
],
"base_experience": 101,
"forms": [
{
"name": "ditto",
"url": "https://pokeapi.co/api/v2/pokemon-form/132/"
}
],
"game_indices": [
{
"game_index": 76,
"version": {
"name": "red",
"url": "https://pokeapi.co/api/v2/version/1/"
}
},
{
"game_index": 76,
"version": {
"name": "blue",
"url": "https://pokeapi.co/api/v2/version/2/"
}
},
{
"game_index": 76,
"version": {
"name": "yellow",
"url": "https://pokeapi.co/api/v2/version/3/"
}
},
{
"game_index": 132,
"version": {
"name": "gold",
"url": "https://pokeapi.co/api/v2/version/4/"
}
},
{
"game_index": 132,
"version": {
"name": "silver",
"url": "https://pokeapi.co/api/v2/version/5/"
}
},
{
"game_index": 132,
"version": {
"name": "crystal",
"url": "https://pokeapi.co/api/v2/version/6/"
}
},
{
"game_index": 132,
"version": {
"name": "ruby",
"url": "https://pokeapi.co/api/v2/version/7/"
}
},
{
"game_index": 132,
"version": {
"name": "sapphire",
"url": "https://pokeapi.co/api/v2/version/8/"
}
},
{
"game_index": 132,
"version": {
"name": "emerald",
"url": "https://pokeapi.co/api/v2/version/9/"
}
},
{
"game_index": 132,
"version": {
"name": "firered",
"url": "https://pokeapi.co/api/v2/version/10/"
}
},
{
"game_index": 132,
"version": {
"name": "leafgreen",
"url": "https://pokeapi.co/api/v2/version/11/"
}
},
{
"game_index": 132,
"version": {
"name": "diamond",
"url": "https://pokeapi.co/api/v2/version/12/"
}
},
{
"game_index": 132,
"version": {
"name": "pearl",
"url": "https://pokeapi.co/api/v2/version/13/"
}
},
{
"game_index": 132,
"version": {
"name": "platinum",
"url": "https://pokeapi.co/api/v2/version/14/"
}
},
{
"game_index": 132,
"version": {
"name": "heartgold",
"url": "https://pokeapi.co/api/v2/version/15/"
}
},
{
"game_index": 132,
"version": {
"name": "soulsilver",
"url": "https://pokeapi.co/api/v2/version/16/"
}
},
{
"game_index": 132,
"version": {
"name": "black",
"url": "https://pokeapi.co/api/v2/version/17/"
}
},
{
"game_index": 132,
"version": {
"name": "white",
"url": "https://pokeapi.co/api/v2/version/18/"
}
},
{
"game_index": 132,
"version": {
"name": "black-2",
"url": "https://pokeapi.co/api/v2/version/21/"
}
},
{
"game_index": 132,
"version": {
"name": "white-2",
"url": "https://pokeapi.co/api/v2/version/22/"
}
}
],
"height": 3,
"held_items": [
{
"item": {
"name": "metal-powder",
"url": "https://pokeapi.co/api/v2/item/234/"
},
"version_details": [
{
"rarity": 5,
"version": {
"name": "ruby",
"url": "https://pokeapi.co/api/v2/version/7/"
}
},
{
"rarity": 5,
"version": {
"name": "sapphire",
"url": "https://pokeapi.co/api/v2/version/8/"
}
},
{
"rarity": 5,
"version": {
"name": "emerald",
"url": "https://pokeapi.co/api/v2/version/9/"
}
},
{
"rarity": 5,
"version": {
"name": "firered",
"url": "https://pokeapi.co/api/v2/version/10/"
}
},
{
"rarity": 5,
"version": {
"name": "leafgreen",
"url": "https://pokeapi.co/api/v2/version/11/"
}
},
{
"rarity": 5,
"version": {
"name": "diamond",
"url": "https://pokeapi.co/api/v2/version/12/"
}
},
{
"rarity": 5,
"version": {
"name": "pearl",
"url": "https://pokeapi.co/api/v2/version/13/"
}
},
{
"rarity": 5,
"version": {
"name": "platinum",
"url": "https://pokeapi.co/api/v2/version/14/"
}
},
{
"rarity": 5,
"version": {
"name": "heartgold",
"url": "https://pokeapi.co/api/v2/version/15/"
}
},
{
"rarity": 5,
"version": {
"name": "soulsilver",
"url": "https://pokeapi.co/api/v2/version/16/"
}
},
{
"rarity": 5,
"version": {
"name": "black",
"url": "https://pokeapi.co/api/v2/version/17/"
}
},
{
"rarity": 5,
"version": {
"name": "white",
"url": "https://pokeapi.co/api/v2/version/18/"
}
},
{
"rarity": 5,
"version": {
"name": "black-2",
"url": "https://pokeapi.co/api/v2/version/21/"
}
},
{
"rarity": 5,
"version": {
"name": "white-2",
"url": "https://pokeapi.co/api/v2/version/22/"
}
},
{
"rarity": 5,
"version": {
"name": "x",
"url": "https://pokeapi.co/api/v2/version/23/"
}
},
{
"rarity": 5,
"version": {
"name": "y",
"url": "https://pokeapi.co/api/v2/version/24/"
}
},
{
"rarity": 5,
"version": {
"name": "omega-ruby",
"url": "https://pokeapi.co/api/v2/version/25/"
}
},
{
"rarity": 5,
"version": {
"name": "alpha-sapphire",
"url": "https://pokeapi.co/api/v2/version/26/"
}
},
{
"rarity": 5,
"version": {
"name": "sun",
"url": "https://pokeapi.co/api/v2/version/27/"
}
},
{
"rarity": 5,
"version": {
"name": "moon",
"url": "https://pokeapi.co/api/v2/version/28/"
}
},
{
"rarity": 5,
"version": {
"name": "ultra-sun",
"url": "https://pokeapi.co/api/v2/version/29/"
}
},
{
"rarity": 5,
"version": {
"name": "ultra-moon",
"url": "https://pokeapi.co/api/v2/version/30/"
}
}
]
},
{
"item": {
"name": "quick-powder",
"url": "https://pokeapi.co/api/v2/item/251/"
},
"version_details": [
{
"rarity": 50,
"version": {
"name": "diamond",
"url": "https://pokeapi.co/api/v2/version/12/"
}
},
{
"rarity": 50,
"version": {
"name": "pearl",
"url": "https://pokeapi.co/api/v2/version/13/"
}
},
{
"rarity": 50,
"version": {
"name": "platinum",
"url": "https://pokeapi.co/api/v2/version/14/"
}
},