CS/SICP in JS
연습문제 1.36
띵킹
2023. 2. 19. 15:21
const tolerance = 0.0001;
function abs(x){
return x > 0 ? x : -x;
}
function fixed_point(f, first_guess) {
function close_enough(x, y) {
return abs(x - y) < tolerance;
}
function try_with(guess) {
const next = f(guess);
display(next);
return close_enough(guess, next)
? next
: try_with(next);
}
return try_with(first_guess);
}
function average(x,y) {
return (x+y)/2;
}
fixed_point(x=> math_log(1000)/math_log(x), 4);
fixed_point(x=> average(x, math_log(1000)/math_log(x)), 4);


728x90