Update function.js

Used ternary operator, instead of if/else.