Skip to content

Instantly share code, notes, and snippets.

@Videmor
Last active October 19, 2015 22:12
Show Gist options
  • Select an option

  • Save Videmor/a1274d2a69c3f95c580c to your computer and use it in GitHub Desktop.

Select an option

Save Videmor/a1274d2a69c3f95c580c to your computer and use it in GitHub Desktop.
Ejercicios Ruby
Given a sentence containing multiple words, find the frequency of a given word in that sentence.
Construct a method named 'find_frequency' which accepts two arguments 'sentence' and 'word', both of which are String objects.
Example: The method, given 'Ruby is The best language in the World' and 'the', should return 2 (comparison should be case-insensitive).
Hint: You can use the method Array#count to count the frequency of any element in the given array. eg:
[9,3,4,9,5].count(9)
Will return the value 2
Given an array containing some strings, return an array containing the length of those strings.
You are supposed to write a method named 'length_finder' to accomplish this task.
Example:
Given ['Ruby','Rails','C42'] the method should return [4,5,3]
Given an Array, return the elements that are present exactly once in the array.
You need to write a method called non_duplicated_values to accomplish this task.
Example: Given [1,2,2,3,3,4,5], the method should return [1,4,5]
Given a sentence, return true if the sentence is a palindrome.
You are supposed to write a method palindrome? to accomplish this task.
Note Ignore whitespace and cases of characters.
Example:
Given "Never odd or even" the method should return true
Número elevado al cuadro, que si al sumar sus dígitos sumen igual al número devolver true,
en caso contrario false.
9 ^ 2 = 81 and 8 + 1 = 9
Problem Statement
Given a custom class MyArray,
write a 'sum' method that takes a block parameter.
Example:
my_array = MyArray.new([1, 2, 3])
my_array.sum gives 6
my_array.sum(10) gives 16
my_array.sum(0) {|n| n ** 2 } gives 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment