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
| let myArray = [1, 2, 3]; | |
| let arraySum = myArray.reduce((previous, current) => previous + current); | |
| console.log('Sum of array values is: ${arraySum}'); |
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
| function copyMachine(arr, num) { | |
| let newArr = []; | |
| while (num >= 1) { | |
| newArr.push([...arr]); | |
| num--; | |
| } | |
| return newArr; | |
| } | |
| // change code here to test different cases: |
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
| let users = { | |
| Alan: { | |
| age: 27, | |
| online: false | |
| }, | |
| Jeff: { | |
| age: 32, | |
| online: true | |
| }, | |
| Sarah: { |
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 bfsComponentSize($matrix) { | |
| $visited = []; | |
| $queue = []; | |
| $componentSize = 0; | |
| for ($i = 0; $i < count($matrix); $i++) { | |
| $visited[] = false; | |
| } | |
| $visited[1] = true; | |
| $queue[] = 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
| <?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 |
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 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); | |
| ?> |
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 | |
| // A simple PHP program to | |
| // find index of given | |
| // Fibonacci number. | |
| function findIndex($n) | |
| { | |
| // if Fibonacci number | |
| // is less than 2, |
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
| /* | |
| CLASS | |
| */ | |
| class Rectangle { | |
| constructor(height, width) { | |
| this.height = height; | |
| this.width = width; | |
| } | |
| get area() { |
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 groupByOwners(array $files) : array | |
| { | |
| $res = []; | |
| foreach($files as $key => $x) | |
| { | |
| $res[$x][] = $key; | |
| } | |
| return $res; | |
| } |
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 unique_names(array $array1, array $array2) : array | |
| { | |
| return array_unique(array_merge($array1, $array2)); | |
| } | |
| $names = unique_names(['Ava', 'Emma', 'Olivia'], ['Olivia', 'Sophia', 'Emma']); | |
| echo join(', ', $names); // should print Emma, Olivia, Ava, Sophia |