Xah Talk Show 2024-04-18 Ep545, ASMR Edition. Keyboard News and JavaScript Coding

/*
f_create_keymap(layout1, layout2)
return a map object.
layout1 is a string.
such as

"
a b c d
"

layout2 is a string.
such as

"
a o e i
"

return a map, such as

[
[a,a]
[b,o]
[c,e]
[d,i]
]

if the strings in the argument is not the same length, return error.

*/

const f_create_keymap = (layout1, layout2) => {
  const xresultMap = new Map([]);
  [...layout1].forEach((item, index) => {
    if (item === layout2[index]) {
    } else {
      xresultMap.set(item, layout2[index]);
    }
  });
  return xresultMap;
};

const layout1 = `
qwertyuiop[]\\
asdfghjkl;'
zxcvbnm,./
`;

const layout2 = `
byou';ldwvz=\\
ciea,.htsnq
gxjk-/rmfp
`;

console.log(f_create_keymap(layout1, layout2));