Word search solver in JavaScript