You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this introductory challenge, your task is to use each of the above three methods to return the text Hello World and others!
defsingle_quote# single quote string here'Hello World and others!'enddefdouble_quote# Double quote string here"Hello World and others!"enddefhere_doc# Here doc string here<<-HERE Hello World and others! HEREend
In this challenge, we practice setting the encoding information for some string of text using Ruby's Encoding methods. Write a function named transcode which takes a ISO-8859-1 encoded string as a parameter, converts it to an UTF8 encoded string, and returns the result.
# Enter your code here.deftranscode(str)str.force_encoding("UTF-8")end
In this challenge, your task is to code a serial_average method which is described below:
It takes a fixed width string in format: SSS-XX.XX-YY.YY. SSS is a three digit serial number, XX.XX and YY.YY are two digit numbers including up to two decimal digits.
It returns a string containing the answer in format SSS-ZZ.ZZ where SSS is the serial number of that input string, and ZZ.ZZ is the average of XX.XX and YY.YY.
All numbers are rounded off to two decimal places.
In this challenge, your task is to code a process_text method, which takes an array of strings as input and returns a single joined string with all flanking whitespace and new lines removed. Each string has to be separated by a single space.
Here are some other ways to access array objects in Ruby.
defneg_pos(arr,index)# return the element of the array at the position `index` from the end of the listarr[-index]enddeffirst_element(arr)# return the first element of the arrayarr.firstenddeflast_element(arr)# return the last element of the arrayarr.lastenddeffirst_n(arr,n)# return the first n elements of the arrayarr.take(n)enddefdrop_n(arr,n)# drop the first n elements of the array and return the restarr.drop(n)end
Arrays provide a variety of methods that allow to add elements to them.
defend_arr_add(arr,element)# Add `element` to the end of the Array variable `arr` and return `arr`arr.push(element)enddefbegin_arr_add(arr,element)# Add `element` to the beginning of the Array variable `arr` and return `arr`arr.unshift(element)enddefindex_arr_add(arr,index,element)# Add `element` at position `index` to the Array variable `arr` and return `arr`arr.insert(index,element)enddefindex_arr_multiple_add(arr,index)# add any two elements to the arr at the indexarr.insert(index,1,2)end