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
[a, b] = [b, a] |
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 min_and_max($list) | |
{ | |
$len = count($list); | |
$minimum = $maximum = $list[0]; | |
$start = 1; | |
if (!($len & 1)) { | |
$start = 0; | |
} |
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 min_and_max($list) | |
{ | |
$len = count($list); | |
$minimum = $maximum = $list[0]; | |
// adding a centinel | |
if ($len % 2 == 0) { | |
$list[] = $list[0]; |
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 | |
$list = array(3,4,2,5,6,7,8,2,5,1,4,4,6); | |
function min_and_max($list) | |
{ | |
$len = count($list); | |
$minimum = $maximum = $list[0]; | |
for ($i = 1; $i < $len; $i++) { | |
if ($minimum > $list[$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
<?php | |
$list = array(3,4,2,5,6,7,8,2,5,1,4,4,6); | |
function maximum($list) | |
{ | |
$len = count($list); | |
$maximum = $list[0]; | |
for ($i = 1; $i < $len; $i++) { | |
if ($maximum < $list[$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
<?php | |
$list = array(3,4,2,5,6,7,8,2,5,1,4,4,6); | |
function minimum($list) | |
{ | |
$len = count($list); | |
$minimum = $list[0]; | |
for ($i = 1; $i < $len; $i++) { | |
if ($minimum > $list[$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
var sequential = function(list, item) { | |
for (var i = 0, l = list.length; i < l; i++) { | |
if (list[i] == item) { | |
return i; | |
} | |
} | |
return -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
(function(root) { | |
function sequential(list, item) { | |
for (var i = 0, l = list.length; i < l; i++) { | |
if (list[i] == item) { | |
return i; | |
} | |
} | |
return -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 | |
// unordered list | |
$arr = array(1, 2, 3, 3.14, 5, 4, 6, 9, 8); | |
// searched value | |
$x = 3.14; | |
$index = null; | |
for ($i = 0; $i < count($arr); $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
array.filter(function(elem, index, self) { | |
return self.indexOf(elem) === index; | |
}); |
NewerOlder