Update index.js

Duplicated code removed.