DEV Community

Discussion on: Daily Challenge #253 - Sort Sentences Pseudo-alphabetically

Collapse
 
miketalbot profile image
Mike Talbot ⭐ • Edited
     result = input=> (input = input.split(' '), [...input.filter(s=>/^[a-z]/.test(s)).sort(), ...input.filter(s=>/^[A-Z]/.test(s)).sort((a,b)=>a===b ? 0 : a < b ? 1 : -1)].join(' '))

If any punctuation "can" be discarded - it isn't.

This if is "must" be discarded:

     result = input=> (input = input.replace(/[^a-zA-Z\s]/g, '').split(' '), [...input.filter(s=>/^[a-z]/.test(s)).sort(), ...input.filter(s=>/^[A-Z]/.test(s)).sort((a,b)=>a===b ? 0 : a < b ? 1 : -1)].join(' '))