Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
418 B
7
Indexable
Never
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(' ');
  
}