Created
August 14, 2016 22:41
-
-
Save Songbird0/ba5aa134248c697cafb131cef3ffa32e to your computer and use it in GitHub Desktop.
This file contains 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 sliceAt(initial_string, target) { | |
var index = initial_string.indexOf(target); | |
if (index !== -1) { | |
switch (index) { | |
case 0: return initial_string.substring(index + target.length); | |
case (initial_string.length - 1): return initial_string.substring(index, target.length - 1); | |
} | |
var first_part = ''; | |
var second_part = ''; | |
first_part = initial_string.substring(0, index); | |
second_part = initial_string.substring(index + 1); | |
return "" + first_part + second_part; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment