Skip to content

Instantly share code, notes, and snippets.

@lancebecker
Created February 18, 2016 20:22
Show Gist options
  • Save lancebecker/585199fb9d6850c82716 to your computer and use it in GitHub Desktop.
Save lancebecker/585199fb9d6850c82716 to your computer and use it in GitHub Desktop.
+angular.module( 'gizmos.filters' ).filter( 'indexToAlphabet', [
+ function() {
+ return function( index, lettercase ) {
+ var index, alphabet, len
+
+ alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ len = ( alphabet.length - 1 )
+
+ if ( lettercase === 'lowercase' ) {
+ alphabet = alphabet.toLowerCase()
+ }
+
+ alphabet = alphabet.split("")
+ index = Math.abs( +index ) || 0
+
+ if ( index > len ) {
+ return alphabet[ 0 ]
+ }
+
+ return alphabet[ index ]
+
+ }
+ }
+]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment