Skip to content

Instantly share code, notes, and snippets.

@spirinvladimir
Created February 20, 2020 10:23
Show Gist options
  • Save spirinvladimir/7689b3b007aa180c8ac1b1afc2588e72 to your computer and use it in GitHub Desktop.
Save spirinvladimir/7689b3b007aa180c8ac1b1afc2588e72 to your computer and use it in GitHub Desktop.
function should replace in string A to B without case sensitive between A and B
function replace_without_case_sensitive (where, from, to) {
return where.toLowerCase().split(from.toLowerCase()).reduce(
(acc, _) =>
[
acc[0] + _.length + from.length,
acc[1].concat(where.substring(acc[0], acc[0] + _.length))
],
[0, []]
)[1].join(to)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment