Skip to content

Instantly share code, notes, and snippets.

@cdutson
Last active December 19, 2015 15:38
Show Gist options
  • Select an option

  • Save cdutson/5977323 to your computer and use it in GitHub Desktop.

Select an option

Save cdutson/5977323 to your computer and use it in GitHub Desktop.
getting a weird iterations abort error in angular when I try to do something very basic, and I HAVE NO IDEA WHY
function WordCtrl($scope, $http) {
/**
* code removed for shortness
**/
// loops through a paragraph's sentences and stitches them together.
$scope.renderSentences = function(paragraph){
var returnVal = [];
for(sentence in paragraph.p.sentences){
if (paragraph.p.sentences.hasOwnProperty(sentence)) {
returnVal.push(renderSentence(paragraph.p.sentences[sentence].sentence));
}
}
return returnVal.join(" ");
};
// workhorse function that stitches a sentence together
var renderSentence = function(sentence) {
var returnVal = [], rand = Math.floor(Math.random()*sentence.words.length-1),
injection = sentence.injection.injection;
angular.forEach(sentence.words, function(w,key){
if(key == 0)
returnVal.push(w.word.capitalize());
else
returnVal.push(w.word);
});
//returnVal[rand] += injection; <!-- this breaks the universe. WHY?!
return returnVal.join(" ") + sentence.ending.ending;
};
}
{
"collection": [
{
"p": {
"sentences": [
{
"sentence": {
"injection": {
"length": 14,
"injection": " you know, and"
},
"words": [
{
"length": 4,
"word": "foof"
},
{
"length": 9,
"word": "Hali"
},
{
"length": 7,
"word": "joe job"
},
{
"length": 4,
"word": "gino"
},
{
"length": 5,
"word": "tuque"
},
{
"length": 7,
"word": "kokanee"
},
{
"length": 3,
"word": "rad"
},
{
"length": 9,
"word": "goal suck"
},
{
"length": 4,
"word": "hose"
},
{
"length": 12,
"word": "buckle bunny"
},
{
"length": 6,
"word": "hoodie"
},
{
"length": 7,
"word": "jawbone"
},
{
"length": 4,
"word": "habs"
},
{
"length": 4,
"word": "flat"
},
{
"length": 13,
"word": "eaves troughs"
},
{
"length": 13,
"word": "Cape Bretoner"
},
{
"length": 7,
"word": "humidex"
},
{
"length": 9,
"word": "housecoat"
}
],
"ending": {
"length": 1,
"ending": "."
}
}
},
{
"sentence": {
"injection": {
"length": 1,
"injection": ","
},
"words": [
{
"length": 7,
"word": "Timbits"
},
{
"length": 11,
"word": "The Islands"
},
{
"length": 11,
"word": "Crappy Tire"
},
{
"length": 13,
"word": "country cable"
},
{
"length": 10,
"word": "jam buster"
},
{
"length": 9,
"word": "Hali"
},
{
"length": 9,
"word": "half-sack"
},
{
"length": 13,
"word": "farmer vision"
},
{
"length": 8,
"word": "pickerel"
},
{
"length": 8,
"word": "washroom"
},
{
"length": 5,
"word": "hosed"
},
{
"length": 5,
"word": "g'way"
},
{
"length": 15,
"word": "had the biscuit"
},
{
"length": 6,
"word": "G.T.A."
}
],
"ending": {
"length": 1,
"ending": "."
}
}
},
{
"sentence": {
"injection": {
"length": 1,
"injection": ";"
},
"words": [
{
"length": 10,
"word": "garburator"
},
{
"length": 4,
"word": "huck"
},
{
"length": 5,
"word": "g'wan"
},
{
"length": 7,
"word": "Giv'n'r"
},
{
"length": 11,
"word": "Horny Tim's"
},
{
"length": 7,
"word": "Gastown"
},
{
"length": 10,
"word": "The Island"
},
{
"length": 7,
"word": "jawbone"
},
{
"length": 7,
"word": "flippin"
},
{
"length": 5,
"word": "tuque"
},
{
"length": 5,
"word": "ginch"
},
{
"length": 5,
"word": "hosed"
},
{
"length": 9,
"word": "bluenoser"
},
{
"length": 4,
"word": "foof"
}
],
"ending": {
"length": 1,
"ending": "."
}
}
},
{
"sentence": {
"injection": {
"length": 1,
"injection": ":"
},
"words": [
{
"length": 4,
"word": "hose"
},
{
"length": 9,
"word": "Hali"
},
{
"length": 6,
"word": "bytown"
},
{
"length": 9,
"word": "half-sack"
},
{
"length": 13,
"word": "lumber jacket"
},
{
"length": 11,
"word": "farmer turn"
},
{
"length": 7,
"word": "gripper"
},
{
"length": 12,
"word": "buckle bunny"
},
{
"length": 10,
"word": "Haligonian"
},
{
"length": 5,
"word": "gorby"
},
{
"length": 10,
"word": "The Hammer"
},
{
"length": 15,
"word": "concession road"
},
{
"length": 7,
"word": "poutine"
},
{
"length": 4,
"word": "deke"
},
{
"length": 6,
"word": "loonie"
},
{
"length": 6,
"word": "head'r"
},
{
"length": 5,
"word": "hosed"
},
{
"length": 10,
"word": "The Island"
}
],
"ending": {
"length": 4,
"ending": " eh!"
}
}
}
]
}
}
]
}
<!-- relevent portion of html -->
<p ng-repeat="para in paragraphs">
{{renderSentences(para)}}
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment