Created
February 20, 2020 10:23
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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