Giter Club home page Giter Club logo

anagram-detector-dumbo-web-102918's Introduction

Anagram Detector

Objectives

  1. Build a class with an initialize method and use an attr_accessor

Description

You will write a program that, given a word and a list of possible anagrams, selects the correct one(s).

Your class, Anagram should take a word on initialization, and instances should respond to a match method that takes an array of possible anagrams. It should return all matches in an array. If no matches exist, it should return an empty array.

In other words, given: "listen" and %w(enlists google inlets banana) the program should return ["inlets"].

listen = Anagram.new("listen")
listen.match(%w(enlists google inlets banana))

# => ["inlets"]

Top Tip: %w(some words) is simply a shortcut for instantiating an array with items in it!

Instructions

Once again, this lab is test-driven. Run the test suite to get started. Remember that you can use the learn/rspec --fail-fast option to run the tests only up until the first failure, in order to work progressively through the tests.

Write your solution in anagram.rb.

Hints:

  • Use an attr_accessor to create a setter and getter method for the word that the Anagram class instances are initialized with.
  • How will you determine if one word is an anagram for another?
    • You'll need to iterate over the array of words that the .match method takes as an argument. You will compare each word of that array to the word that the Anagram class is initialized with.
    • To determine if they are anagrams, try determining if they are composed of the same letters. Remember that you can split a word into an array of letters using some_word.split(""). You can compare two arrays using the ==. For example:
[1, 2, 3] == [1, 2, 3]
=> true

[1, 3, 2] == [1, 2, 3]
=> false

Two arrays are equal if they contain the same elements, in the same order. Remember that you can .sort an arrays elements. This will help in your comparison:

[1, 3, 2].sort == [3, 2, 1].sort
=> true

Resources

View Anagram Detector on Learn.co and start learning to code for free.

anagram-detector-dumbo-web-102918's People

Contributors

ahimmelstoss avatar annjohn avatar aviflombaum avatar babyshoes avatar benjagross avatar deniznida avatar drewprice avatar fislabstest avatar flatiron-bot avatar fs-lms-test-bot avatar gj avatar howardbdev avatar jmburges avatar kthffmn avatar loganhasson avatar louisasm avatar sarogers avatar sophiedebenedetto avatar

Watchers

 avatar  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.