javascript - How to split a string in equal halves -
i'm trying simulate simple evolution thing using binary code. each individual in "gene pool" has own unique string in binary code.
in order have them mate, need take half of 1 string, , other half of , merge them. problem is, don't know how split string in 2 equal halves, , totally random.
help appreciated, thanks!
well total length of string , first half doing string.slice(firstindex, secondindex). make first index 0 , secondindex equal string.length / 2. return first half of string , can figure out second half of string string.slice(string.length / 2, string.length).
Comments
Post a Comment