D
D
Dmitri19982021-10-06 17:14:29
typescript
Dmitri1998, 2021-10-06 17:14:29

What is wrong with replay?

The code throws an error

return tmp[len].replace(/{name}/g, (item, i) : string =>

export const likes = (a: string[]) : string => {
  let len: number;
  let tmp: string[] = [
    "no one",
    "{name}",
    "{name}, {name}",
    "{name}, {name}, {name} ",
    "{name}, {name} and others"
  ]
  a.length > 3 ? len = 4 : len = a.length;
  console.log(tmp[len]);
  return tmp[len].replace(/{name})/g, (item, i) : string => {
     if(item == '{name}') return a[i];
  })
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexandroppolus, 2021-10-06
@pacan4ik

/{name} ) /g - extra parenthesis

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question