JS
function sort(sentence){ const wordReg = /\w+/; const isCapitalized = /^[A-Z]/; const words = sentence .split(' ') .map(w => wordReg.exec(w)[0]) .sort((a, b) => { const aCapital = isCapitalized.test(a); const bCapital = isCapitalized.test(b); if(aCapital !== bCapital) { return aCapital ? 1 : -1; } return a.localeCompare(b) * (aCapital ? -1 : 1); }) return words.join(' '); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
JS