GithubHelp home page GithubHelp logo

pfwtfp-practice-with-array-characters-lab's Introduction

Practice with Arrays of Strings

Introduction

In this lab, we'll solidify our understanding of how array characters work and how to perform various operations on them.

Learning Goals

  • Perform operations on arrays

Perform Operations on Arrays

Your task is to write the implementations for a set of methods. Each method takes in an array of strings and manipulate those strings in a specific way. These methods should work with any array of strings.

  1. sentence_to_array(string) - Takes in a string. Returns an array of individual words from the string, separated using whitespace.
sentence_to_array('Earth has not anything to show more fair')
# => ['Earth', 'has', 'not', 'anything', 'to', 'show', 'more', 'fair']
  1. clean_up_elements(array) - Takes in an array. Returns a new array of strings in which all leading and trailing whitespaces have been removed and some special characters replaced with whitespaces. Removes any nil or empty string values in the array
clean_up_elements([' hello', nil, '  and ', '', 'goodbye ', nil])
# => ['hello', 'and', 'goodbye']
  1. array_to_sentence(array) - Takes in an array. Returns an string of joined array values. The first word should be capitalized.
array_to_sentence('and', 'all', 'that', 'mighty', 'heart', 'is', 'lying', 'still')
# => 'And all that mighty heart is lying still'
  1. capitalize_all_elements(array) - Takes in an array. Returns a new array in which the first character of every string capitalized
capitalize_all_elements(['see', 'spot', 'run'])
# => ['See', 'Spot', 'Run']
  1. substitute_strings(array, pattern, replacement) - Takes in an array, a pattern, and replacement. Returns a new array in which all strings that match the pattern have been substituted by the replacement. Substitutions should be case sensitive.
substitute_strings(['go', 'dog', 'Go'], 'go', 'yo')
# => ['yo', 'dog', 'Go']
  1. title_format(array) - Takes in an array. Returns a new array in which all strings have been formatted as titles. The first letter of the first word is always capitalized. The first letter of every other word in a string is also capitalized, with the exception of articles, conjunctions and prepositions. Arrays of exceptions are provided in lib/array_practice.rb
title_format(['for whom the bell tolls', 'the rime of the ancient mariner', 'composed upon westminster bridge',])
# => ['For Whom the Bell Tolls', 'The Rime of the Ancient Mariner', 'Composed Upon Westminster Bridge']

Write implementations for each method in lib/array_practice.rb. Run learn to see your progress.

Conclusion

In web development, we often need to our programs to take in and interpret user input. Users, however, are human, and prone to typos and unique formatting.

Arrays can be a handy tool when handling text and strings. They give us the ability to manipulate and change strings in bulk. With them, we can take human language and convert it something a computer can use. Or alternatively, take something a computer generated and make it more human friendly.

Resources

pfwtfp-practice-with-array-characters-lab's People

Contributors

cjbrock avatar maxwellbenton avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pfwtfp-practice-with-array-characters-lab's Issues

Specs failing

The final 2 specs in this exercise is failing the asked requirements as it is copied code from the previous exercise.

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.