JSFiddle - React, Tailwind, and code Playground
by wvega
JavaScript
let questions = [1, 2, 3, 4, 5, 6, 7, 8];
let answers = [1, 2];
let combinations = questions.slice(1).reduce(function(accumulator, question) {
var newAccumulator = [];
accumulator.forEach(function(combination) {
newAccumulator.push(combination.concat([1]));
newAccumulator.push(combination.concat([2]));
});
return newAccumulator;
}, [[1],[2]]);
function tryCombination(index) {
let combination = combinations[index];
let data = {
respuestaPregunta1: combination[0],
respuestaPregunta2: combination[1],
respuestaPregunta3: combination[2],
respuestaPregunta4: combination[3],
respuestaPregunta5: combination[4],
respuestaPregunta6: combination[5],
respuestaPregunta7: combination[6],
respuestaPregunta8: combination[7],
}
let url = 'https://transacciones.proteccion.com/MultifondosOBLWEB/cuestionarioCondicionesModificacionPerfil.ctl';
jQuery.post(url, data, function(data) {
if (data.indexOf('DEBE INTENTARLO DE NUEVO') === false) {
console.log('La combinación correcta es: ' + combination.join(', '));
} else {
console.log('La siguiente combinación falló: ' + combination.join(', '));
setTimeout(function() { tryCombination(index + 1); }, 2000);
}
});
}
setTimeout(function() { tryCombination(0); }, 100);
/*
combinations.some(function(combination) {
let data = {
respuestaPregunta1: combination[0],
respuestaPregunta2: combination[1],
respuestaPregunta3: combination[2],
respuestaPregunta4: combination[3],
respuestaPregunta5: combination[4],
respuestaPregunta6: combination[5],
respuestaPregunta7: combination[6],
respuestaPregunta8: combination[7],
}
let url = 'https://transacciones.proteccion.com/MultifondosOBLWEB/cuestionarioCondicionesModificacionPerfil.ctl';
jQuery.post(url, data, function(data) {
if (data.indexOf('DEBE INTENTARLO DE NUEVO') === false) {
console.log('La combinación correcta es: ' + combination.join('1, 2'));
...