Skip to content

Commit

Permalink
mobile beauty
Browse files Browse the repository at this point in the history
  • Loading branch information
glathoud committed Aug 27, 2018
1 parent d3568bd commit 3db6e21
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 60 deletions.
14 changes: 12 additions & 2 deletions index.html
Expand Up @@ -15,8 +15,7 @@
.clear { clear: both; }
.text-center { text-align: center; }

.intro { margin: auto; max-width: 600px; text-align: justify;
line-height: 1.5em;
.intro { margin: auto; text-align: justify;
margin-top: 1.5em;
}
.intro code { line-height: normal; }
Expand All @@ -34,12 +33,23 @@
width: calc( 100% - 2em );
padding: 1em;
}

@media screen and (max-width: 999px) {
.right, pre, button, .code_cont_header { font-size: 1.8em; }
pre button { font-size: 1.2em; }
#speedtest_output { font-size: 0.85em; }
h3 { margin-top: 3em; }
}

@media screen and (min-width: 1200px) {
.intro { max-width: 600px;
line-height: 1.5em;
}
.code_cont {
width: calc( 50% - 2em );
}
}

.code_cont_header {
margin-top: 2em;
background-color: lightgrey;
Expand Down
17 changes: 11 additions & 6 deletions lib/sorted_search.js
Expand Up @@ -15,11 +15,12 @@ var global, exports;
, improveLast = mfun( improveFirst, improveLast )
;

function sortedSearch(sortedArray, x, /*?fun?*/less, /*?fun?*/equal)
function sortedSearch
(sortedArray, x, /*?fun?*/less, /*?fun?*/equal)
/*
In a sorted array, search for first & last occurences of `x`.
If `x` found, return `[ first_index, last_index ]` (integers).
If `x` found,return `[ first_index, last_index ]` (integers).
If `x` not found, return `null`.
*/
Expand All @@ -36,7 +37,8 @@ var global, exports;
;

return improveFirst(
sortedArray, x, less, equal, isFirstFound, isLastFound
sortedArray, x, less, equal
, isFirstFound, isLastFound
, first_found, last_found, i, j, imax, jmin
);
}
Expand All @@ -54,7 +56,8 @@ var global, exports;
function isLastFound( sortedArray, j, equal, x)
{
return equal(x, sortedArray[j]) &&
(j > sortedArray.length - 2 || !equal(x, sortedArray[j + 1]));
(j > sortedArray.length - 2
|| !equal(x, sortedArray[j + 1]));
}

// --- Private details
Expand Down Expand Up @@ -102,7 +105,8 @@ var global, exports;

return mret(
improveLast
, sortedArray, x, less, equal, isFirstFound, isLastFound
, sortedArray, x, less, equal
, isFirstFound, isLastFound
, first_found, last_found, i, j, imax, jmin
);
}
Expand Down Expand Up @@ -140,7 +144,8 @@ var global, exports;

return mret(
improveFirst
, sortedArray, x, less, equal, isFirstFound, isLastFound
, sortedArray, x, less, equal
, isFirstFound, isLastFound
, first_found, last_found, i, j, imax, jmin
);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/sorted_search_closure.js
Expand Up @@ -37,7 +37,7 @@ var global, exports;
/*
In a sorted array, search for first & last occurences of `x`.
If `x` found, return `[ first_index, last_index ]` (integers).
If `x` found,return `[ first_index, last_index ]` (integers).
If `x` not found, return `null`.
*/
Expand Down Expand Up @@ -71,7 +71,8 @@ var global, exports;
function isLastFound( sortedArray, j, equal, x)
{
return equal(x, sortedArray[j]) &&
(j > sortedArray.length - 2 || !equal(x, sortedArray[j + 1]));
(j > sortedArray.length - 2
|| !equal(x, sortedArray[j + 1]));
}

// --- Private details
Expand Down
67 changes: 41 additions & 26 deletions lib/sorted_search_closure_unittest.js
Expand Up @@ -5,35 +5,50 @@ var global, exports;

'use strict';

global.get_test_arr_sorted_search_closure = get_test_arr_sorted_search_closure;
global.get_test_arr_sorted_search_closure =
get_test_arr_sorted_search_closure;

function get_test_arr_sorted_search_closure()
{
return [

function sorted_search_closure_test()
{
var sortedArray = [ 0, 0, 0, 0, 1, 1, 3, 4, 6, 6, 7, 8, 9, 10, 10, 10,
11, 13, 14, 14, 15 ];
assert( '"0###3" === sortedSearchClosure( v, 0 ).join("###")', sortedArray );
assert( '"4###5" === sortedSearchClosure( v, 1 ).join("###")', sortedArray );
assert( 'null === sortedSearchClosure( v, 2 )', sortedArray );
assert( '"8###9" === sortedSearchClosure( v, 6 ).join("###")', sortedArray );
assert( 'null === sortedSearchClosure( v, 12 ) ', sortedArray );
assert( '"18###19" === sortedSearchClosure( v, 14 ).join("###")', sortedArray );
assert( '"20###20" === sortedSearchClosure( v, 15 ).join("###")', sortedArray );

return true;

function assert(codestring, /*?optional?*/v)
{
if (!new Function( 'v', 'return ' + codestring + ';' )( v ))
throw new Error( 'Failed test: ' + codestring );
}
}

];

return [ sorted_search_closure_test ];
}



function sorted_search_closure_test()
{
var sortedArray =
[ 0, 0, 0, 0, 1, 1, 3, 4, 6, 6, 7, 8, 9, 10, 10, 10,
11, 13, 14, 14, 15 ];

function f( s ) { assert( s, sortedArray ); }

f( '"0###3" === sortedSearchClosure( v, 0 ).join("###")' );

f( '"4###5" === sortedSearchClosure( v, 1 ).join("###")' );

f( 'null === sortedSearchClosure( v, 2 )' );

f( '"8###9" === sortedSearchClosure( v, 6 ).join("###")' );

f( 'null === sortedSearchClosure( v, 12 )' );

f
('"18###19" === sortedSearchClosure( v, 14 ).join("###")');

f
('"20###20" === sortedSearchClosure( v, 15 ).join("###")');

return true;

function assert(codestring, /*?optional?*/v)
{
var tmp_f =
new Function( 'v', 'return ' + codestring + ';' );

if (!tmp_f( v ))
throw new Error( 'Failed test: ' + codestring );
}
}

})(global || exports || this);
56 changes: 32 additions & 24 deletions lib/sorted_search_unittest.js
Expand Up @@ -9,31 +9,39 @@ var global, exports;

function get_test_arr_sorted_search()
{
return [

function sorted_search_test()
{
var sortedArray = [ 0, 0, 0, 0, 1, 1, 3, 4, 6, 6, 7, 8, 9, 10, 10, 10,
11, 13, 14, 14, 15 ];
assert( '"0###3" === sortedSearch( v, 0 ).join("###")', sortedArray );
assert( '"4###5" === sortedSearch( v, 1 ).join("###")', sortedArray );
assert( 'null === sortedSearch( v, 2 )', sortedArray );
assert( '"8###9" === sortedSearch( v, 6 ).join("###")', sortedArray );
assert( 'null === sortedSearch( v, 12 ) ', sortedArray );
assert( '"18###19" === sortedSearch( v, 14 ).join("###")', sortedArray );
assert( '"20###20" === sortedSearch( v, 15 ).join("###")', sortedArray );
return [ sorted_search_test ];
}

return true;

function assert(codestring, /*?optional?*/v)
{
if (!new Function( 'v', 'return ' + codestring + ';' )( v ))
throw new Error( 'Failed test: ' + codestring );
}
}
function sorted_search_test()
{
var sortedArray =
[ 0, 0, 0, 0, 1, 1, 3, 4, 6, 6, 7, 8, 9, 10, 10, 10,
11, 13, 14, 14, 15 ];
assert( '"0###3" === sortedSearch( v, 0 ).join("###")'
, sortedArray );
assert( '"4###5" === sortedSearch( v, 1 ).join("###")'
, sortedArray );
assert( 'null === sortedSearch( v, 2 )'
, sortedArray );
assert( '"8###9" === sortedSearch( v, 6 ).join("###")'
, sortedArray );
assert( 'null === sortedSearch( v, 12 ) '
, sortedArray );
assert( '"18###19" === sortedSearch( v, 14 ).join("###")'
, sortedArray );
assert( '"20###20" === sortedSearch( v, 15 ).join("###")'
, sortedArray );

return true;

function assert(codestring, /*?optional?*/v)
{
var tmp_f =
new Function( 'v', 'return ' + codestring + ';' );

];

if (!tmp_f( v ))
throw new Error( 'Failed test: ' + codestring );
}
}

})(global || exports || this);

0 comments on commit 3db6e21

Please sign in to comment.