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
| // key will be 0,1,2,... | |
| Collection::macro('transpose', function() { | |
| $items = array_map(function(...$items) { | |
| return $items; | |
| }, ...$this->values()); | |
| return new self($items); | |
| }); | |
| // transpose(['name', 'email']) |
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 permutations(array $array) { | |
| if (count($array) == 0) { | |
| return []; | |
| } elseif (count($array) == 1) { | |
| return $array; | |
| } else { | |
| $results = []; | |
| for ($i = 0; $i < count($array); $i ++) { |
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
| # -------------- | |
| # User Instructions | |
| # | |
| # Write a function, longest_subpalindrome_slice(text) that takes | |
| # a string as input and returns the i and j indices that | |
| # correspond to the beginning and end indices of the longest | |
| # palindrome in the string. | |
| # | |
| # Grading Notes: | |
| # |
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
| #------------------ | |
| # User Instructions | |
| # | |
| # Hopper, Kay, Liskov, Perlis, and Ritchie live on | |
| # different floors of a five-floor apartment building. | |
| # | |
| # Hopper does not live on the top floor. | |
| # Kay does not live on the bottom floor. | |
| # Liskov does not live on either the top or the bottom floor. | |
| # Perlis lives on a higher floor than does Kay. |
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 | |
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
| public function rules() | |
| { | |
| $user = User::find($this->users); | |
| switch($this->method()) | |
| { | |
| case 'GET': | |
| case 'DELETE': | |
| { | |
| return []; |
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
| #include <cstdio> | |
| #include <stdlib.h> | |
| using namespace std; | |
| struct Node | |
| { | |
| int data; | |
| Node* next; | |
| }; |
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
| Array.prototype.nextPermutation = function() { | |
| var i = this.length - 1; | |
| while (i > 0 && this[i - 1] >= this[i]) { | |
| i --; | |
| } | |
| if (i <= 0) return false; | |
| var j = this.length - 1; | |
| while (this[j] <= this[i - 1]) { | |
| j --; |
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 | |
| use League\Flysystem\Filesystem; | |
| use League\Flysystem\Adapter\Local; | |
| require __DIR__ . '/vendor/autoload.php'; | |
| $container = new Slim\Container; | |
| $container['filesystem'] = function($container) { |
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
| define(function() { | |
| var subscribers = {}; | |
| function subscribe (type, fn) { | |
| if (! subscribers[type]) { | |
| subscribers[type] = []; | |
| } | |
| if (subscribers[type].indexOf(fn) == -1) { | |
| subscribers[type].push(fn); | |
| } |