js reusable in array function