Skip to content

Instantly share code, notes, and snippets.

View sedera-tax's full-sized avatar

Razafindrakoto Yannick Sedera Aina sedera-tax

View GitHub Profile
@sedera-tax
sedera-tax / fileOwners.php
Created January 15, 2021 13:38
1. File Owners Associative arrays Easy Implement a groupByOwners function that: Accepts an associative array containing the file owner name for each file name. Returns an associative array containing an array of file names for each owner name, in any order. For example, for associative array ["Input.txt" => "Randy", "Code.py" => "Stan", "Output…
<?php
function groupByOwners(array $files) : array
{
$res = [];
foreach($files as $key => $x)
{
$res[$x][] = $key;
}
return $res;
}
@sedera-tax
sedera-tax / class.js
Last active November 5, 2020 12:20
Tuto ES6
/*
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;
@sedera-tax
sedera-tax / script.js
Created June 29, 2018 10:25
Generate an Array of All Object Keys with Object.keys()
let users = {
Alan: {
age: 27,
online: false
},
Jeff: {
age: 32,
online: true
},
Sarah: {
@sedera-tax
sedera-tax / index.js
Created June 28, 2018 13:23
Spread operator ES6
function copyMachine(arr, num) {
let newArr = [];
while (num >= 1) {
newArr.push([...arr]);
num--;
}
return newArr;
}
// change code here to test different cases:
@sedera-tax
sedera-tax / index.js
Created June 28, 2018 12:36
Somme Array reduce
let myArray = [1, 2, 3];
let arraySum = myArray.reduce((previous, current) => previous + current);
console.log('Sum of array values is: ${arraySum}');
@sedera-tax
sedera-tax / freecodecamp-build-a-tribute-page.markdown
Created June 20, 2018 07:06
freeCodeCamp : Build a Tribute Page