Dada una cuadrícula de caracteres en el rango ascii[az], reorganice los elementos de cada fila alfabéticamente, de forma ascendente. Determine si las columnas también están en orden alfabético ascendente, de arriba a abajo. Devuelva SÍ si lo son o NO si no lo son.
const gridOrig = ["ebacd", "fghij", "olmkn", "trpqs", "xywuv"]; function gridChallenge(grid) { // Write your code here let gridOne = []; let gridTwo = []; for (let i = 0; i < grid.length; i++) { gridOne.push(grid[i].split("")); // console.log(gridOne); }//this section makes each element of the array become array for (let i = 0; i < gridOne.length; i++) { gridTwo.push(gridOne[i].sort()); // console.log(gridTwo); }//this section sort each element of the parent array let answer = []; for (let i = 0; i < gridTwo.length - 1; i++) { for (let j = 0; j < gridTwo[i].length; j++) { if (gridTwo[i][j] <= gridTwo[i + 1][j]) { // debugger; // console.log("true"); answer.push("YES"); } else if (undefined) { answer = "NO"; } else { // console.log("false"); answer.push("NO"); } } } // console.log(answer); let finalAns = "NO"; if (answer.includes("NO")) { finalAns = "NO"; } else { finalAns = "YES"; } console.log(finalAns); //I can see it on the console return finalAns; // this returns nothing } gridChallenge(gridOrig);Devuelve el resultado, simplemente no lo usas. Prueba esto:
const gridChallengeResult = gridChallenge(gridOrig); // saving returned value to variable console.log(gridChallengeResult) // logging it to the console