@@ -32,10 +32,12 @@ rl.question("> ", (input) => {
3232 // ---------------------
3333
3434 // JUMLAH KELAS (PAKAI RUMUS STURGES) -------
35- const k = Math . ceil ( 1 + 3.3 * Math . log10 ( n ) ) ;
35+ const kReal = 1 + 3.3 * Math . log10 ( n ) ;
36+ const k = Math . ceil ( kReal ) ;
3637
3738 // ITERVAL KELAS ---------------------
38- const interval = Math . ceil ( range / k ) ;
39+ const iReal = range / k ;
40+ const interval = Math . ceil ( iReal ) ;
3941
4042 // KELAS BAWAH DIKURANGI 0.5, HITUNG FREKUENSI, DAN INTERVAL --------------
4143 const kelas = [ ] ;
@@ -53,22 +55,31 @@ rl.question("> ", (input) => {
5355 batasBawah = batasAtas ;
5456 }
5557
56- // Cetak hasil
5758 console . log ( "\n=== TABEL DISTRIBUSI FREKUENSI ===" ) ;
5859 console . log ( `Jumlah data (n): ${ n } ` ) ;
5960 console . log ( `Data terkecil (min): ${ min } ` ) ;
6061 console . log ( `Data terbesar (max): ${ max } ` ) ;
6162 console . log ( `Range (R): ${ range } ` ) ;
62- console . log ( `Jumlah kelas (k): ${ k } ` ) ;
63- console . log ( `Interval kelas (i): ${ interval } ` ) ;
63+
64+ console . log ( "\nLangkah-langkah perhitungan:" ) ;
65+ console . log ( "1. Rumus jumlah kelas (Sturges): k = 1 + 3.3 * log10(n)" ) ;
66+ console . log ( ` → k = 1 + 3.3 * log10(${ n } )` ) ;
67+ console . log (
68+ ` → k = 1 + 3.3 * ${ Math . log10 ( n ) . toFixed ( 4 ) } = ${ kReal . toFixed ( 4 ) } `
69+ ) ;
70+ console . log ( ` → Setelah dibulatkan → k = ${ k } ` ) ;
71+
72+ console . log ( "\n2. Rumus interval kelas: i = R / k" ) ;
73+ console . log ( ` → i = ${ range } / ${ k } = ${ iReal . toFixed ( 4 ) } ` ) ;
74+ console . log ( ` → Setelah dibulatkan → i = ${ interval } ` ) ;
75+
6476 console . log ( "\n| Interval Kelas | Frekuensi |" ) ;
6577 console . log ( "|------------------|-----------|" ) ;
66-
6778 kelas . forEach ( ( kls ) => {
6879 const intervalText = `${ kls . batasBawah } - ${ kls . batasAtas } ` . padEnd ( 16 ) ;
6980 console . log ( `| ${ intervalText } | ${ kls . frekuensi . toString ( ) . padEnd ( 9 ) } |` ) ;
7081 } ) ;
71-
7282 console . log ( "|------------------|-----------|" ) ;
83+
7384 rl . close ( ) ;
7485} ) ;
0 commit comments