// console.log("certain position");
let form = document.querySelector('[name=verify')
let greenLetters = document.querySelectorAll('.greenLetters')
let certain_pos_words_data = document.getElementById('certain_pos_words_data')
greenLetters[0].focus()
let certain_pos_count = document.querySelector('#certain_pos_count')
let certain_pos_error_msg = document.querySelector('#certain_pos_error_msg')
let certain_pos_submit = document.getElementById('certain_pos_submit')
let newWordsLength
let errMessage = document.querySelector('.errMessage')
let spinner = document.querySelector('.spinner')
const wordsInCertainPos = async (letters, lettersWithIndex,wordLength) => {
let maxLength = Math.max.apply(null, wordLength);
// maxLength = maxLength + 1
try {
let result = ''
document.querySelector('#searchData').innerHTML = ''
spinner.classList.add('spinner-border')
certain_pos_count.innerHTML = 'Finding words in certain position...'
let response = await fetch('/.netlify/functions/wordsInCertainPositions', {
method: 'POST',
body: JSON.stringify({
greenLetters: letters,
greenWithIndex: lettersWithIndex,
}),
})
let data = await response.json()
if(data.length == 0){
errMessage.innerHTML = 'Sorry!! No words found'
errMessage.classList.add('alert-danger')
errMessage.style.display = 'block'
document.querySelector('#searchData').innerHTML = 'Search'
spinner.classList.remove('spinner-border')
certain_pos_words_data.innerHTML = ""
certain_pos_count.innerHTML = ""
newWordsLength = 0
}
else{
errMessage.innerHTML = ''
errMessage.classList.remove('alert-danger')
data = data.slice(0,1500)
document.querySelector('#searchData').innerHTML = 'Search'
spinner.classList.remove('spinner-border')
certain_pos_words_data.innerHTML = ""
newWordsLength = 0
let ok = true
for (let i = maxLength; i <= 15; i++) {
let newdata = data.filter((item) => item.length === i)
if (newdata.length === 0) {
certain_pos_words_data.innerHTML += ''
} else {
newWordsLength += newdata.length
certain_pos_error_msg.classList.remove('alert-danger')
certain_pos_error_msg.innerHTML = ''
const result = newdata.map((item) => {
if (item.length === 1) {
ok = false
newWordsLength = newWordsLength - 1
} else {
let ScrabbleLetterScore = ScrabbleScore()
sum = 0
item = item.toLowerCase()
for (let i = 0; i < item.length; i++) {
sum += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
}
return `