I solved a problem in javascript, but When I execute the code I get a result which is:'A', but I would like to know if it is good what I coded because I have doubts.
Here is the problem:
printChar
allows to display one and only one ASCII character from A to Z (inclusive) on several lines and
columns (graphic representation called "ASCII Art").
We want to perform the operation in the other direction: obtain a character from its representation
graphic.
Implement the scanChar (str)
method so that it returns the character c associated with its representation
graph (i.e. str = printChar (c)).
If str does not match a character between A and Z (inclusive), then scanChar should return the character '?'
here is my code:
function scanChar(str) {
// Iterate over each character from A to Z.
for (var c = 'A'; c <= 'Z'; c++) {
// Check to see if the character corresponds with the ASCII art.
if (printChar(c) === str) {
// Return the character if it does.
return c;
}
}
// Optionally use a '?' character to indicate that the string passed
// doesn't correspond to any valid ASCII art.
return '?';
}
function printChar( s) {
return "S";
}
var art=printChar('A');
console.log(scanChar(art));
question from:
https://stackoverflow.com/questions/65649676/implement-a-function-in-javascript 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…