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 = count($arr); | |
while ($arr[$index--] != $x); | |
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; | |
$length = count($arr); | |
$index = null; | |
for ($i = 0; $i < $length; $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
(function() { | |
var sequential = function(haystack, needle) { | |
var i = 0, | |
len = haystack.length | |
; | |
for (; i < len; i++) { | |
if (haystack[i] === needle) { | |
return true; | |
} |
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 | |
/** | |
* Performs a sequential search using sentinel | |
* and changes the array after the value is found | |
* | |
* @param array $arr | |
* @param mixed $value | |
*/ | |
function sequential_search(&$arr, $value) | |
{ |
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 eratosthenes_sieve(&$sieve, $n) { | |
$i = 2; | |
while ($i <= $n) { | |
if ($sieve[$i] == 0) { | |
echo $i; | |
$j = $i; | |
while ($j <= $n) { |
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; | |
}); |
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
(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
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
<?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]) { |
OlderNewer