Last active
November 23, 2016 10:03
-
-
Save lukabot/3c251c4339bf4c517b37552d28d9e38d to your computer and use it in GitHub Desktop.
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 f(str, seperator, limit) { | |
// split string by limit | |
// .split eventually add one more elements. | |
let arr = str.split(seperator, limit); | |
if(typeof limit === "number") { | |
// find last element's index, push it to the original array | |
let index = arr.reduce(function(prev, curr, i){ | |
return str.indexOf(curr, prev); | |
}, 0); | |
arr.pop(); | |
arr.push(str.substring(index)); | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment