This file contains hidden or 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 | |
/* | |
Objectives: | |
- Create PHP script that will translate input data to expected output from example below. | |
- Calculate time complexity of your script | |
bonus: Implement solution that will not use pass-by-reference and will not use objects | |
*/ | |
$input = [ | |
'A' => 1, |
This file contains hidden or 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
# if not running interactively, don't do anything | |
[ -z "$PS1" ] && return | |
# Detect platform | |
platform='unknown' | |
unamestr=`uname` | |
if [[ "$unamestr" == 'Linux' ]]; then | |
platform='linux' | |
elif [[ "$unamestr" == 'FreeBSD' ]]; then | |
platform='freebsd' |
This file contains hidden or 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 | |
function array_group_by (array $array, callable $mapping) | |
{ | |
$buckets = []; | |
foreach ($array as $item) { | |
$key = $mapping($item); | |
if (!isset($buckets[$key])) { | |
$buckets[$key] = [$item]; | |
} else { | |
$buckets[$key][] = $item; |