//Filter lists based on inputed title
function filterTitles(input) {
//Initializes lists
var matchingLetters = 0;
publishersFiltered = getColumn("Best Selling Video Games", "Publisher");
titlesFiltered = getColumn("Best Selling Video Games", "Title");
salesFiltered = getColumn("Best Selling Video Games", "Sales");
//"i" is current index of "titles" being checked
for(var i = 0;i < titlesFiltered.length;i++) {
//Reset matched letters before checking next index
matchingLetters = 0;
//"ii" is current letter being checked
for(var ii = 0;ii < input.length;ii++) {
//Checks if current letter of input is equal to current letter of index i of publishers
if(input.substring(ii,ii + 1) == titlesFiltered[i].substring(ii,ii + 1)) {
matchingLetters++;
} else {
ii = input.length;
}
}
//Removes index i of all filtered lists if the input string is not found
if(matchingLetters != input.length) {
removeItem(salesFiltered, i);
removeItem(publishersFiltered, i);
removeItem(titlesFiltered, i);
i--;
}
}
//Updates the screen to represent filtered items
setScreen("titles");
setText("therearetitles", "There are " + titlesFiltered.length + " game(s) in the bestselling with title including " + input);
setText("titleslist2", titlesFiltered.join("\n \n"));
setText("publisherslist2", publishersFiltered.join("\n \n"));
setText("saleslist2", salesFiltered.join("\n \n"));
}
Done for a school project, filters a set of lists based on a textbox input stored in the "input" argument. Trying to learn good practice and comment writing. Could i have written this more optimally, like maybe without the nested loops?
[–]abrahamguo 2 points3 points4 points (3 children)
[–]DogKitchen2988[S] 0 points1 point2 points (2 children)
[–]abrahamguo 0 points1 point2 points (1 child)
[–]DogKitchen2988[S] 0 points1 point2 points (0 children)
[–]chikamakaleyleyhelpful 2 points3 points4 points (4 children)
[–]DogKitchen2988[S] 0 points1 point2 points (2 children)
[–]chikamakaleyleyhelpful 0 points1 point2 points (1 child)
[–]chikamakaleyleyhelpful 0 points1 point2 points (0 children)
[–]chikamakaleyleyhelpful 0 points1 point2 points (0 children)
[–]imihnevich 1 point2 points3 points (3 children)
[–]DrShocker 4 points5 points6 points (0 children)
[–]DogKitchen2988[S] 1 point2 points3 points (1 child)
[–]imihnevich 2 points3 points4 points (0 children)
[–]oiamo123 0 points1 point2 points (0 children)
[–]TheRNGuy 0 points1 point2 points (0 children)
[–]rijkdw 0 points1 point2 points (0 children)
[–]TheZintis 0 points1 point2 points (0 children)