updated the coded to pass array as parameter