|
// This is an old way of doing it, I made a more dynamic version using the other two files, the codepen reflects the updated version |
|
|
|
export const keymap = { |
|
alphabet: ['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'], |
|
|
|
// Vowels |
|
a: ['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ͣ'], |
|
e: ['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ͤ'], |
|
i: ['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ͥ'], |
|
o: ['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ͦ'], |
|
u: ['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ͧ'], |
|
|
|
// Consonants |
|
c: ['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ͨ'], |
|
d: ['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ͩ'], |
|
h: ['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ͪ'], |
|
m: ['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ͫ'], |
|
r: ['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ͬ'], |
|
t: ['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ͭ'], |
|
v: ['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ͮ'], |
|
x: ['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ͯ'], |
|
}; |
|
|
|
export default function findDualWord = (w1, w2) => { |
|
w1 = w1.split(''); |
|
w2 = w2.split(''); |
|
let illegal = 0; |
|
|
|
return w1.reduce((total, original, position) => { |
|
let index = keymap.alphabet.findIndex(item => item === original.toLowerCase()); |
|
|
|
if(index === -1){ |
|
illegal++; |
|
return total += original; |
|
} |
|
|
|
let character = w2[position - illegal]; |
|
|
|
if(character && keymap[character.toLowerCase()]){ |
|
return total += keymap[character.toLowerCase()][index]; |
|
} |
|
|
|
return total += original; |
|
}, ''); |
|
}; |
Hi