Forked from Free Code Camp's Pen wMQrXV.
A Pen by Razafindrakoto on CodePen.
<?php | |
function groupByOwners(array $files) : array | |
{ | |
$res = []; | |
foreach($files as $key => $x) | |
{ | |
$res[$x][] = $key; | |
} | |
return $res; | |
} |
/* | |
CLASS | |
*/ | |
class Rectangle { | |
constructor(height, width) { | |
this.height = height; | |
this.width = width; | |
} | |
get area() { |
<?php | |
// A simple PHP program to | |
// find index of given | |
// Fibonacci number. | |
function findIndex($n) | |
{ | |
// if Fibonacci number | |
// is less than 2, |
<?php | |
function killKthBit($n, $k) { | |
return (strlen(base_convert((string) $n,10,2))-$k >= 0) ? (int) base_convert(substr_replace(base_convert((string) $n,10,2),'0',strlen(base_convert((string) $n,10,2))-$k,1),2,10) : (int) $n; | |
} | |
echo killKthBit(2147483647, 31); | |
?> |
<?php | |
/** | |
* | |
* Exports an associative array into a CSV file using PHP. | |
* | |
* @see https://stackoverflow.com/questions/21988581/write-utf-8-characters-to-file-with-fputcsv-in-php | |
* | |
* @param array $data The table you want to export in CSV | |
* @param string $filename The name of the file you want to export | |
* @param string $delimiter The CSV delimiter you wish to use. The default ";" is used for a compatibility with microsoft excel |
<?php | |
function bfsComponentSize($matrix) { | |
$visited = []; | |
$queue = []; | |
$componentSize = 0; | |
for ($i = 0; $i < count($matrix); $i++) { | |
$visited[] = false; | |
} | |
$visited[1] = true; | |
$queue[] = 1; |
let users = { | |
Alan: { | |
age: 27, | |
online: false | |
}, | |
Jeff: { | |
age: 32, | |
online: true | |
}, | |
Sarah: { |
function copyMachine(arr, num) { | |
let newArr = []; | |
while (num >= 1) { | |
newArr.push([...arr]); | |
num--; | |
} | |
return newArr; | |
} | |
// change code here to test different cases: |
let myArray = [1, 2, 3]; | |
let arraySum = myArray.reduce((previous, current) => previous + current); | |
console.log('Sum of array values is: ${arraySum}'); |
Forked from Free Code Camp's Pen wMQrXV.
A Pen by Razafindrakoto on CodePen.