Logic behind graphical accents in Spanish
const endingLetters = ['n', 's', 'a', 'e', 'i', 'o', 'u']
const accentWord = myWord => {
let syllables = WordUtils.splitIntoSyllables(myWord)
let numberOfSyllables = syllables.length
if ( WordUtils.getWordType(myWord) === 'esdrújula' ) {
syllables[numberOfSyllables - 3].addAccent() // example: o RÉ ga no || bo LÍ gra fo
return syllables.join('')
}
if ( WordUtils.getWordType(myWord) === 'grave' && !endingLetters.includes(myWord.split('')[0]) ) {
syllables[numberOfSyllables - 2].addAccent() // examples: ven-TA-na !== MÁS-ter
return syllables.join('')
}
if ( WordUtils.getWordType(myWord) === 'aguda' && endingLetters.includes(myWord.split('')[0]) ) {
syllables[numberOfSyllables - 1].addAccent() // examples ca-ra-COL !== ra-TÓN
}
}
const WordUtils = {
getWordType: word => {
let syllablesArr = this.splitIntoSyllables(word)
let numberOfSyllables = syllablesArr.length
let tonic
syllablesArr.forEach(syllable, i) {
tonic = syllable.isTonic() && syllable
}
switch (i) {
case: numberOfSyllables - 1:
return 'aguda'
break
case: numberOfSyllables - 2:
return 'grave'
break
case: numberOfSyllables - 3:
return 'esdrújula'
break
default:
return 'sobreesdrújula'
}
},
splitIntoSyllables: word => {
// weird things here
}
}