This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shortenName(string $name): string | |
{ | |
$words = explode(' ', $name); | |
$shortened = ''; | |
foreach ($words as $word) { | |
// Take the first letter of each word and concatenate | |
$shortened .= strtoupper(substr($word, 0, 1)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// fix this error please | |
class DBConnection | |
{ | |
private $connection; | |
public function __construct($connection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// di berikan sebuah angka, cari posisi index angka tersebut dalam array | |
// input : arr = [1, 2, 3, 4, 5], i = 3 | |
// output : 2 | |
// input : arr = [1, 2, 3, 4, 5], i = 9 | |
// output : -1 | |
function findMe($arr, $i) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// hilangkan semua item yang duplikat dalam sebuah array | |
// contoh input : [1, 1, 2, 3, 4, 4, 5] | |
// maka output nya : [1, 2, 3, 4, 5] | |
function removeAllDuplicates($arr) | |
{ | |
return $arr; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// Tugas 1 | |
print("Hello world"); | |
// Tugas 2 | |
String name = 'joko anton jodo'; | |
print(name); | |
// Tugas 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user www-data; | |
worker_processes auto; | |
pid /run/nginx.pid; | |
events { | |
worker_connections 768; | |
} | |
http { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Complete this function, that count how much odd number in an array | |
// example : | |
// payload : [1, 2, 3, 4, 5, 6, 7] | |
// the result is 4 | |
function countOdd($numbers) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Manhattan Distance : | |
// Buatlah sebuah fungsi untuk menghitung 'manhattan distance' antara 2 titik koordinat, contoh: | |
// | |
// A = (2, 2) | |
// B = (3, 5) | |
// | |
// |x1 - x2| + |y1 - y2| | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// counting the altitude | |
// 1. 'up' berarti naik 1 (+1) | |
// 2. 'down' berarti turun 1 (-1) | |
// 3. 'flat' berarti datar (+0) | |
// anda memiliki sebuah array 'arr' yang berisi : ['up', 'up', 'down', 'flat'] | |
// buatlah program untuk menentukan ketinggian akhir berdasarkan aturan di atas | |
// arr = ['up', 'up', 'down', 'flat'], maka hasil nya adalah 1, karena naik 2 kali, turun 1 kali, dan datar 1 kali -> (2 * 1) - 1 + 0 = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// negative positive ratio | |
// anda memiliki sebuah array 'arr' yang berisi : [-1, 1, 2] | |
// buatlah program untuk menentukan rasio (berupa bilangan pecahan) antara jumlah bilangan negatif dibandingkan bilangan positif | |
// arr = [-1, 1, 2], maka hasil nya adalah 0.5, karena jumlah bilangan negatif nya 1 dan bilangan positif nya 2 -> 1 / 2 = 0.5 | |
$arr = [-1, -1, 1, 2]; | |
$result1 = 0; // 1 |
NewerOlder