Untitled
unknown
javascript
4 years ago
418 B
11
Indexable
export function order(words: string): string {
const splittedPhrases = words.split(' ');
const orderred = splittedPhrases.reduce((accumulator, phrase) => {
const copyPhrase = phrase.repeat(1);
const currentPosition = copyPhrase.replace( /^\D+/g, '')[0];
return {
[currentPosition] : phrase,
...accumulator
};
}, {});
return Object.values(orderred).join(' ');
}Editor is loading...