Skip to content

Instantly share code, notes, and snippets.

@brianmugweru
Created August 22, 2022 00:17
Show Gist options
  • Save brianmugweru/e9f37ed6cffc64b624fbeac0e2e71d3c to your computer and use it in GitHub Desktop.
Save brianmugweru/e9f37ed6cffc64b624fbeac0e2e71d3c to your computer and use it in GitHub Desktop.
function WordSplit(strArr) {
const firstComparisonString = strArr[0]
const dictionaryItems = strArr[1].split(',')
let result = 'not possible'
for (let i = 0; i <= firstComparisonString.length; i++) {
const firstMatch = firstComparisonString.substring(0, i)
const lastMatch = firstComparisonString.substring(i, firstComparisonString.length)
if (dictionaryItems.includes(firstMatch) && dictionaryItems.includes(lastMatch)) {
result = `${firstMatch},${lastMatch}`
break
}
}
return result
}
// keep this function call here
console.log(WordSplit(readline()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment