I am trying to filter some content by alphabetical letter. ie(A=Animal, Arts,etc, B=Bug, Bit, Bat, etc).
I have it working for one letter at a time, which is ok I guess, but I rather have ranges like A-C, D-F,G-I etc.
Here is the code I am working with
package {
import flash.display.Sprite;
public class Array_filter extends Sprite {
private var _letterRange:Array=new Array("A","B","C");
private var _showsArray:Array=new Array("Mythbusters","Alphabet Goop","Brick and Brack","Dominio","Cats","Frogs and Pricess","Daniel Cook");
public function Array_filter() {
_showsArray.sort();
var _showsArrayCopy:Array=_showsArray.map(arrayToUpperCase);
var _showsFilteredArray:Array=_showsArrayCopy.filter(filterByLetter);
trace(_showsFilteredArray);
}
private function arrayToUpperCase(element:String, index:int, array:Array):String {
return (element.toUpperCase());
}
private function filterByLetter(element:String, index:int, array:Array):Boolean {
for(var i=0;i<_letterRange.length;i++) {
return element.charAt(0)==_letterRange*;
}
}
}
}
The problem I am having is in the filterByLetter function as I can’t use a loop as it is giving me the following error:
1170:Function does not return a value
If I comment out the for loop and replace the index of the loop with a number instead of i it gives back the proper result.
Any suggestions?
Thanks in advance