foldRight implemented using foldLeft and reverse function