function gridChallenge(grid) {
let sortedRows = [];
for(let i = 0; i < grid.length; i++){
let sortedRow = grid[i].split('').sort().join('')
sortedRows.push(sortedRow)
}
let columns = []
let sortedColumns = columns.sort()
for(let z = 0; z < sortedRows.length; z++){
let column = sortedRows[z].split('')[0]
columns.push(column)
}
if(columns === sortedColumns){
console.log("YES")
} else {
console.log("NO")
}
}
The code is working completely fine in the IDE and showing the expected output but when I tried to run the same code in HackerRank it is showing that the code is giving undefined as output. And I've also tried with other problems it is giving the same result.