I
I
ignis212021-06-28 12:50:48
JavaScript
ignis21, 2021-06-28 12:50:48

How to double every character in a string?

How to make a doubling of each character?

For example: Ihor-> IIhhoorr.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-06-28
@ignis21

''.concat(...Array.from(str, n => n.repeat(2)))
or or or or
str.replace(/./g, '$&$&')
str.replace(/./g, m => Array(3).join(m))
[...str].flatMap(n => Array(2).fill(n)).join('')
str.split('').reduce((acc, n) => acc + n + n, '')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question