首页 > 解决方案 > 我想去意大利化这个功能

问题描述

我怎样才能使这个功能更好?我不喜欢必须使用 aforEach来定义可操作内容的事实。我正在考虑在 find 上运行 reduce,但这对我来说太混乱了。

_replace (content, find, replace, delimiter = '', findDelimiter = '') {
  if (!Array.isArray(find)) find = [find]
  let result = content
  find.forEach(ref => {
    result = result.split(findDelimiter).reduce((a, e) => a + delimiter + (this._reference[replace][this._reference[ref].indexOf(e)] || e), '')
  })
  return result
}

标签: node.js

解决方案


推荐阅读