**I have the expected result when I test solution in any browser or editor but when I test it within the FreeCode Camp I can’t pass the Test and after the first run it gives incorrect result
Expected Result: [[27,82,41,124…8,4,2,1], [351, 77031]]
**
**function hailstoneSequence() {
//find longest hailstone sequence
let firstPart = seqNum(27);
for (var n, max = 0, i = 100000; --i;) {
var seq = seqNum(i), sLen = seq.length;
if (sLen > max) {
n = i;
max = sLen;
}
}
return [firstPart, [max,n]];
}
//first part return seq arr
function seqNum(num) {
var seq = [num];
while (num > 1) {
let check = num % 2;
if (check == 0) {
num = num / 2;
seq.push(num);
} else {
num = (num * 3) + 1;
seq.push(num);
}
}
return seq;
}
console.log(hailstoneSequence())
**
function hailstoneSequence() {
//find longest hailstone sequence
let firstPart = seqNum(27);
for (var n, max = 0, i = 100000; --i;) {
var seq = seqNum(i), sLen = seq.length;
if (sLen > max) {
n = i;
max = sLen;
}
}
return [firstPart, [max,n]];
}
//first part return seq arr
function seqNum(num) {
var seq = [num];
while (num > 1) {
let check = num % 2;
if (check == 0) {
num = num / 2;
seq.push(num);
} else {
num = (num * 3) + 1;
seq.push(num);
}
}
return seq;
}
console.log(hailstoneSequence())
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36
.
Challenge: Hailstone sequence
Link to the challenge:
https://www.freecodecamp.org/learn/coding-interview-prep/rosetta-code/hailstone-sequence