N
N
NickelFace2018-06-13 11:32:34
JavaScript
NickelFace, 2018-06-13 11:32:34

Working with a string, how to implement it?

At the input there is a sentence, it ends with a dot. Any length.
Input example: "Hello world!"
At the output: "rivetP irm!"
+ Possibility to add any lowercase character or a letter at the end of a word
Input example: "Hello world"
Output: "rivetP98 irm98"
How to implement this in JavaScript?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-06-13
@NickelFace

const src = 'Привет мир!';
const suffix = '98';
const srcArr = src.split(' ');
const reversed = srcArr.map(el => el.split('').reverse().join(''));
const target = reversed.map(el => el+suffix).join(' ');
console.log(target);

or
const src = 'Привет мир!';
const suffix = '98';
const target = src.split(' ').map(el => el.split('').reverse().join('')+suffix).join(' ');
console.log(target);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question