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 diagonalDifference($arr) { | |
//initialize a new array to hold the diagonals, left and right | |
$rightD = []; | |
$leftD = []; | |
//iterate through the parent array, taking note of it's key | |
foreach($arr as $key => $lineArray) | |
{ | |
//iterate through the diagonal lines, take note of the keys | |
foreach ($lineArray as $innerKey => $value){ |
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 miniMaxSum($arr) { | |
$sumValue = []; | |
foreach($arr as $key => $integer) | |
{ | |
$sumValue[] = array_sum(array_filter($arr, function($innerKey) use ($key){ | |
return $innerKey !== $key; | |
},ARRAY_FILTER_USE_KEY)); | |
} |
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
//PROBLEM | |
//There is a large pile of socks that must be paired by color. | |
//Given an array of integers representing the color of each sock, | |
//determine how many pairs of socks with matching colors there are. | |
//More details about problem can be found here | |
//https://www.hackerrank.com/challenges/sock-merchant/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=warmup | |
function sockMerchant($n, $ar) { | |
// Get the unique version of the array and the count of value appearance. |
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
<!-- Staircase detail | |
This is a staircase of size 4: | |
# | |
## | |
### | |
#### | |
Its base and height are both equal to . It is drawn using # symbols and spaces. The last line is not preceded by any spaces. |
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 | |
class Food | |
{ | |
} | |
class AnimalFood extends Food | |
{ | |
} |
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 | |
//a boy has two shows and can decide to wear anyone of it at any time, | |
//the below class shows the implementation without applying any design patterns | |
class ShoeWithoutFactory | |
{ | |
const CHURCH = 1; | |
const SCHOOL = 2; |
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 | |
class Browser | |
{ | |
public static function browse($callable) | |
{ | |
$params = (new ReflectionFunction($callable))->getParameters(); | |
$args = []; |
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 | |
class Person{ | |
public $name; | |
public function __construct(string $name){ | |
$this->name = $name; | |
} | |
} |
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 | |
//NULLSAFE OPERATOR | |
//class User { | |
// public function profile(){ | |
// return new Profile; | |
// } | |
//} | |
// |
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
<!-- | |
Copyright 2018 Google Inc. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software |