Git Product home page Git Product logo

phase-3-lecture-videos-enumerables's Introduction

Video: Enumerables

<iframe src="https://player.vimeo.com/video/593547595/?title=0&byline=0&portrait=0" width="640" height="360" allowfullscreen="allowfullscreen" allow="autoplay; fullscreen; picture-in-picture"></iframe> require 'pry' # enumarables in hashes books = [ { title: 'Intro to Ruby Programming: Begginers Guide Series', price: 25.9, author: 'John Telder', publisher: 'comedy.com', rating: 3.5, description: 'Great intro to ruby for new programmers' }, { title: 'The Ruby Programming Langauage', price: 13.99, author: 'Yukihiro Matsumoto', publisher: "O'rilley", rating: 4, description: 'A thorough look into the fundamentals of Ruby programming' }, { title: 'The Ruby Programming Language', price: 24.11, author: 'David Flanagan', publisher: 'Kindle', rating: 4.5, description: 'Everything You Need to Know' }, { title: 'Beginning Ruby 3: From Beginner to Pro ', price: 23.99, author: 'Carleton DiLeo and Peter Cooper', publisher: 'APRESS', rating: 4.0, description: 'A good series from beginner to pro' }, { title: 'Polished Ruby Programming', price: 51.99, author: 'Jeremy Evans', publisher: 'Kindle', rating: 4.5, description: 'Build better software with more intuitive, maintainable, scalable, and high performance ruby code' }, { title: 'The Well-Grounded Rubyist', price: 49.99, author: 'David A. Black and Joseph Leo 111', publisher: 'eTextbook', rating: 4.0, description: 'Great intro to ruby concepts' }, { title: 'Practical Object-oriented Design', price: 44.99, author: 'Sandi Metz', publisher: 'Kindle', rating: 5.0, description: 'An Agile Premier Using Ruby' } ]

each method: loops through array

def print_books books.each { |b| puts b } puts b end

collect method: returns a new array based on some conditions

titles = books.collect {|b| b[:title]}

select method: filters out elements based on a condition

cheaper = books.select { |b| b[:price] > 28 }

find method: finds first element matching the given condition

author = books.find { |b| b[:author] == 'Yukihiro Matsumoto'}

sum method: sums total for all elements

total = books.sum { |b| b[:price] }

max method: finds highest value in an array

best_book = books.max { |b| b[:rating] }

binding.pry

phase-3-lecture-videos-enumerables's People

Contributors

ihollander avatar prince475 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.