logic seems to work; need to fix/figure out finalArr or how to return the final result