Last active
          October 19, 2019 20:18 
        
      - 
      
- 
        Save vinicius5581/004d3257bb9ca4298a0e0a2a6dd3c993 to your computer and use it in GitHub Desktop. 
    Array basics
  
        
  
    
      This file contains hidden or 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 frutas = ['Maçã', 'Banana']; | |
| const fruits = ["Maçã", "Manga", "Uva", "Laranja", "Maçã", "Manga", "Banana", "Banana"] | |
| console.log('adciona no comeco - unshift') | |
| console.log(frutas.unshift('Laranja')) | |
| console.log(frutas) | |
| console.log('remove no comeco - shift') | |
| console.log(frutas.shift()) | |
| console.log(frutas) | |
| console.log('adciona no final - push') | |
| console.log(frutas.push('Amora')) | |
| console.log(frutas) | |
| console.log('remove do final - pop') | |
| console.log(frutas.pop()); | |
| console.log(frutas); | |
| , 'Amora', 'Laranja', 'Limao' | |
| for (let i = 2; i < frutas.length; i = i + 1) { | |
| console.log(`com loop: ${frutas[i]}`) | |
| } | |
| for (let fruta in frutas) { | |
| console.log(`com simple loop: ${frutas[fruta]}`) | |
| } | |
| frutas.forEach(function(fruta) { | |
| console.log(`fruta: ${fruta}`) | |
| }) | |
| const count = fruits.reduce((c,v) => (c[v] = (c[v] || 0) + 1, c),{}); | |
| // Group by in objects | |
| const groupBy = (xs, key) => xs.reduce((rv, x) => ({...rv, [x[key]]: [...(rv[x[key]] || []), x]}), {}); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment