# Soal Soal Test Coding

May 24th, 2022 (edited)
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. ## Function Factorial (JS)
2. function factorial(n){
4.     if(n == 0 || n == 1){
6.     }else{
7.         for(var i = n; i >= 1; i++){
9.         }
11.     }
12. }
13.
14. let n = 4;
17.
18. ########################################################
19.
20. ## Membulatkan angka desimal kebawah (JS)
21. var decimalDown = Math.floor(1.6)
22. console.log("Decimal down menjadi" + decimalDown)
23.
24. #######################################################
25.
26. ## Membulatkan angka desimal ke atas (JS)
27. var decimalUp = Math.round(1.7)
28. console.log("Decimal up menjadi" + decimalUp)
29.
30. #######################################################
31.
32. ## Membalik kata (JS)
33. const str = "Joko Purnomo"
34. const reverseWords = str => {
35.     let reversed = '';
36.     reversed = str.split(' ')
37.     .map(word => {
38.         return word
39.         .split("")
40.         .reverse()
41.         .join("");
42.     })
43.     .join(" ")
44.     return reversed
45. }
46.
47. console.log("Membalik huruf" + reverseWords(str))
48.
49. #######################################################
50.
51. // [PHP] Menghitung beberapa detik kedepan
52. \$date = date_create('08:52:45');
53. \$d = date_add(\$date, date_interval_create_from_date_string('5000 second'));
54. echo date_format(\$d, 'H:i:s') . "\n";
55.
56. #######################################################
57.
58. // [PHP] Menghitung total pecahan uang yang berada di Array
59. function hitung(\$uang)
60. {
61.
62.     \$pecahan = [100000, 50000, 20000, 5000, 1000, 50];
63.     \$pec = [];
64.     \$a = \$uang;
65.     for (\$i = 0; \$i <= 5; \$i++) {
66.         \$pec = \$a % \$pecahan[\$i];
67.         \$b = (\$a - \$pec) / \$pecahan[\$i];
68.         \$a = \$pec;
69.
70.         echo "Pecahan ke " . \$pecahan[\$i] . " = " . \$b . "\n";
71.     }
72. }
73. echo hitung(1895250) . "\n";
74.
75. #######################################################