Created
October 17, 2014 22:56
-
-
Save Kreijstal/6169fef30298adbc284e 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 agrupateBy3CharacterGroups(words){ | |
var wordsAnswer=[],wordGroups=[],word; | |
for(var i=0;i<words.length;i++){ | |
word=Word3Chars(words[i]); | |
for(var _i=0;;_i++){ | |
if(!wordGroups[_i]){wordGroups[_i]=word;wordsAnswer[_i]=words[i];break}else{ | |
if(wordsAnswer[_i].length<120&&!hasSharedChildren(wordGroups[_i],word)){ | |
wordsAnswer[_i]+=" "+words[i];wordGroups[_i]=wordGroups[_i].concat(word);break | |
} | |
} | |
} | |
} | |
return wordsAnswer | |
} | |
function Word3Chars(word){ | |
var a=[] | |
for(var i=0;i<word.length-2;i++){ | |
//console.log(word.substr(i+2,1)) | |
if(word.substr(i+2,1)===" ")i+=3; | |
if(word.substr(i+1,1)===" ")i+=2; | |
a.push(word.substr(i,3).trim()) | |
} | |
return a; | |
} | |
function hasSharedChildren(array1,array2){ | |
for(var i=0;i<array1.length;i++){ | |
if(array2.indexOf(array1[i])!==-1)return true | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment