I want to reduce duplication in my JavaScript syntax.
No matter how much I think about it, it doesn't come to mind.
It doesn't matter if it is for loop or any syntax!
i add some of case and result
if if it is correct answer would be result
// case 1
// const max = [1, 31, 0, 0]
// const min = [1, 31];
// result = [3, 5]
// case 2
// const max = [0, 0, 0, 0, 0, 0]
// const min = [0, 0]
// result = [1, 6]
// case 3
// const max = [45, 4, 35, 20, 3, 9]
// const min = [45, 4, 35, 20, 3, 9]
// result = [1, 1]
if (max.length === 6) {
answer[0] = 1;
} else if (max.length === 5) {
answer[0] = 2;
} else if (max.length === 4) {
answer[0] = 3;
} else if (max.length === 3) {
answer[0] = 4;
} else if (max.length === 2) {
answer[0] = 5;
} else {
answer[0] = 6;
}
if (min.length === 6) {
answer[1] = 1;
} else if (min.length === 5) {
answer[1] = 2;
} else if (min.length === 4) {
answer[1] = 3;
} else if (min.length === 3) {
answer[1] = 4;
} else if (min.length === 2) {
answer[1] = 5;
} else {
answer[1] = 6;
}
answer = [7-max.length, 7-min.length];answer[0] = max.length <= 6 ? 7 - max.length : 6;andanswer[1] = min.length <= 6 ? 7 - min.length : 6;.maxandminmay look like. Sort-of like test cases, I think. And theresultis what is expected. And, case 2 - does seem incorrect to me.