In the first line, the input is the line d. In the second line, a series of words separated by a dot is entered. You need to output these words by separating each word with a combination of d characters. (В первой строке на вход подается строка d. Во второй строке вводится ряд слов через точку. Вам нужно вывести эти слова, разделяя каждое слово сочетанием символов d.)
example:
Sample Input: d= /|
dej.fow.orj.jkk.fgo.pwk.pkp.lde.efe
Sample Output:
dej/|fow/|orj/|jkk/|fgo/|pwk/|pkp/|lde/|efe
let d=prompt();
let b=prompt();
let arr=b.split('');
for(let i in arr) {
if(i.indexOf('.') !== -1){
arr = i.replace(i.indexOf('.'), d)
}
}
arr = arr.join()
console.log(arr)`
It doesn’t work!
4
Answers
Concatenate characters with replacing the dot:
Array::reduce()
version:A benchmark:
Escape the special characters
(escape) and Regex’s
.
(any character) using backslash:\
.
Mr . has a blue house and a . car.
let str = document.getElementById("demo").innerHTML;
let res = str.replace(/./g, "d");
OutPut:
Mr d has a blue house and a d car.
It seems like you’re trying to replace the dots in the input string b with the character d. However, there are a few issues in your code. You can achieve this by using the split and join methods correctly. Here’s the corrected code:
With this code, it will correctly split the input string b by dots and then join the elements with the character d, giving you the desired output.