Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function buildTable() {
- keyboard = [
- 'QWERTYUIOPqwertyuiop'.split(''),
- 'ASDFGHJKLasdfghjkl'.split(''),
- 'ZXCVBNMzxcvbnm'.split(''),
- ];
- var table = {};
- for (var i = 0; i < 3; i++) {
- keyboard[i].forEach(function(e) {
- table[e] = i;
- });
- }
- return table;
- }
- function check(table, str) {
- freq = [0, 0, 0];
- str = str.split('');
- str.forEach(function(e) {
- freq[table[e]]++;
- });
- var num_zeroes = 0;
- freq.forEach(function(e) {
- num_zeroes += (freq[e] == 0);
- });
- return num_zeroes == 2;
- }
- var table = buildTable();
- inputs = ['Alaska', 'dad', 'hello',];
- inputs.forEach(function(e) {
- if (check(table, e)) console.log(e);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement