Reputation: 35
I am trying to make a program that receives a string and returns the percentage of Cs and Gs in the first 5 and in the last 5 positions, if the string has less than 20 chars, the function should return the percentage in the complete sequence. However, I've already been able to get you to give me only the percentage of Cs and Gs, but I do not know how to check in the first 5 positions and the finals.
function' :: [Char] -> Double
function' xs = fromIntegral final0 / fromIntegral final1
where final0 = length $ filter (\x-> x == 'C'|| x == 'G') xs
final1 = length xs
Upvotes: 0
Views: 220
Reputation: 1310
You can get the fist 5 elements of a string s
using take 5 s
, and the last 5 using take 5 $ reverse s
.
Upvotes: 2