Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- text = "source text banana banana banana ..."
- // Transcoding map to convert keybords characters sequence to natural numbers: { 'q' => 0, 'w' => 1, ... }
- characterCodesMap = "qwertyuiopasdfghjklzxcvbnm".mapWithIndex((character, index) => { return [character, index] }).toHash
- // Character code ranges for keyboard rows
- row1 = 0..9
- row2 = 10..18
- row3 = 19..25 // Actually this one will never be used
- // Loop through each word
- text.eachWord((word) => {
- inRange1 = true
- inRange2 = true
- inRange3 = true
- word.each((character) => {
- code = characterCodesMap[character]
- // Range inclusion check function suppose to work like this:
- // includes = (value) => { return (range1.first >= code) && (range1.last <= code) }
- inRange1 = inRange1 && code.inRange(row1)
- inRange2 = inRange2 && !inRange1 && code.inRange(row2)
- // Last range check is simplified
- inRange3 = inRange3 && !(inRange1 || inRange2)
- // Continue to the next work after range test fails first time
- if (!(inRange || inRange || inRange)) break;
- })
- if (inRange1) print("'#{word}' belongs to row 1")
- if (inRange2) print("'#{word}' belongs to row 2")
- if (inRange3) print("'#{word}' belongs to row 3")
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement