In Ruby, you can build a new array from ranges by using the built in method
.to_a or the
Array method. If we need to create a range of years from 2010 to 2020, you would do it like
Array (2010..2020) . Inside the parenthesis we are giving Ruby two numbers and two dots, which Ruby interprets as creating an inclusive range from 2010 to 2020.
As seen above, and inclusive range creates an array for of all the numbers between and including the ones that invoked it.
Ruby also allows us to call the same two methods with three dots, which would create a new array that would exclude the specified highest value.
Calling our range method with three dots
2010...2020 creates an array for all the numbers from 2010–2019, and does not include 2020. As you can see, very easy and simple to create a range with specified parameters. In Ruby, the range functionality doesn’t only stop at numbers! Letters, conditionals, and even intervals can all use the built in range methods to produce some easy to read and compute functionality in our code.
.to_a and the
for loop, we could loop through the numbers and push them into the array until we reach our higher number and break the loop.
for loop would change to
i < 2020. While this is great, our use for continuously returning a range from 2010 to 2020 is rather limited. Our next change would be to write this to accept arguments, so that the code could perform a variety of tasks, and not just for this past decade. Writing this to be more dynamic would involve making a function that takes in two arguments for our range numbers.
Does your business need an interactive website or app?
The technology used to develop the overall app by the developers from WebClues Infotech is at par with the latest available technology.
For more inquiry click here https://bit.ly/31eZyDZ
Book Free Interview: https://bit.ly/3dDShFg
So, head over to your terminal and create a folder LineThroughEffect. Create three files -index.html, main.js and styles.css inside it. We are also opening the files in VS Code.
Now, we will add the basics html in index.html and also link both css and js files. We have very little html in this project, with div with id of line and an h1 with an id of text.