Get rid of redundant console.log()
This commit is contained in:
parent
908901f883
commit
c9fc5b0842
@ -206,5 +206,71 @@ function design4(input) {
|
||||
}
|
||||
return outputString;
|
||||
}
|
||||
var charIterateState;
|
||||
function charIterate(input) {
|
||||
if (charIterateState < input.length) {
|
||||
charIterateState++;
|
||||
} else {
|
||||
charIterateState = 0;
|
||||
}
|
||||
return charIterateState;
|
||||
}
|
||||
|
||||
function design5(input) {
|
||||
let outputString = "";
|
||||
let outputLine = "";
|
||||
input += " ";
|
||||
let radius = (input.length);
|
||||
let mid = radius;
|
||||
if (mid % 2 == 1) {
|
||||
var spaceOffset = " ";
|
||||
} else {
|
||||
var spaceOffset = "";
|
||||
}
|
||||
console.log(radius, mid);
|
||||
// dist represents distance to the center
|
||||
let dist = parseFloat(0);
|
||||
let space = ""
|
||||
for (let i = 0; i < (input.length / 2); ++i) {
|
||||
space += " ";
|
||||
}
|
||||
// for horizontal movement
|
||||
var i;
|
||||
var j;
|
||||
let lineHasInput = false;
|
||||
for (i = 0; i <= 2 * radius; i++) {
|
||||
lineHasInput = false;
|
||||
if (Math.trunc(i) != mid) {
|
||||
// for vertical movement
|
||||
for (j = 0; j <= 2 * radius; j++) {
|
||||
dist = Math.sqrt(
|
||||
((i - radius) * (i - radius) * 4) + // (* 4) accounts for the offset between lines
|
||||
(j - radius) * (j - radius)
|
||||
);
|
||||
//console.log(i, j, radius, dist);
|
||||
// dist should be in the range (radius - 0.5)
|
||||
// and (radius + 0.5) to print stars(*)
|
||||
|
||||
|
||||
if (dist > radius - 1 && dist < radius + 1) { //&& dist > radius - 1
|
||||
lineHasInput = true;
|
||||
outputLine += input.charAt(charIterate);
|
||||
} else {
|
||||
outputLine += " ";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lineHasInput = true;
|
||||
outputLine += input.charAt(charIterate) + space + input + space + spaceOffset + input.charAt(charIterate);
|
||||
}
|
||||
|
||||
//console.log(i, j, outputLine);
|
||||
if (lineHasInput) {
|
||||
outputString += outputLine + "\n";
|
||||
}
|
||||
outputLine = "";
|
||||
}
|
||||
return outputString;
|
||||
}
|
||||
//console.log(design4("super long test string super long test string"));
|
||||
//"super long test string super long test string"
|
Loading…
Reference in New Issue
Block a user