Guest User

Untitled

a guest
Feb 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. var letters = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ];
  2. var leetChars = ['@', '8', '(', '|)', '3', 'ph', 'g', '#','l', '_|', '|<', '1', "|'|'|", '/\/', '0', '|D', '(,)', '|2', '5', '+', '|_|', '|/', "|/|/'",'><', 'j', '2'];
  3.  
  4.  
  5. function translate(string) {
  6. // first, since all letter in array are lowercased, we will need to make our string lowercased.
  7. // we will need to create an empty string for the new leet word
  8. // next we will need to loop through each character of the string
  9. // for each character index, we will need to pull the letter index
  10. // then we will need to to pull the respective index from the leetChars array and add it to the new string
  11.  
  12. var lowercased = string.toLowerCase();
  13. var leetString = '';
  14. var charIndex = null;
  15.  
  16. for(var i = 0; i < lowercased.length; i++) {
  17. charIndex = letters.indexOf(lowercased[i]);
  18. leetString += leetChars[charIndex];
  19. }
  20. return leetString;
  21. }
  22.  
  23. translate('Fullstack') // => 'ph|_|115+@(|<'
Add Comment
Please, Sign In to add comment