functional.js solution