SHARE
TWEET

Untitled

a guest Apr 19th, 2019 120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function buildTable() {
  2.   var table = {}
  3.   keyboard = [
  4.     "qwertyuiop".split(''),
  5.     "asdfghjkl".split(''),
  6.     "zxcvbnm".split(''),
  7.   ]
  8.   for (var row = 0; row < keyboard.length; row++) {
  9.     for (var col = 0; col < keyboard[row].length; col++) {
  10.         table[keyboard[row][col]] = row;
  11.     }
  12.   }
  13.   return table;
  14. };
  15.  
  16. function valid(table, chars) {
  17.   for (var i = 1; i < chars.length; i++){
  18.     if (table[chars[i]] != table[chars[i-1]]) {
  19.       return false;
  20.     }
  21.   }
  22.   return true;
  23. };
  24.  
  25. table = buildTable();
  26. console.log(table);
  27.  
  28. const inputs = ['Alaska', 'Dad', 'apple']
  29. for (var i = 0; i < inputs.length; i++) {
  30.   if (valid(table, inputs[i].toLowerCase())) {
  31.     console.log('[VALID ROW] ' + inputs[i]);
  32.   }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top