Using the reduce and reduceByKey methods to calculate the results