16 - Arrays with One Type
Arrays with one type
by steen_hansen
HTML
<!DOCTYPE html><meta charset="utf-8" />
<title>16 Arrays with One Type</title>
<div id='js-div' style="width:48%">
<a href='https://github.com/steenhansen/type-czech' target="_blank" class='git-hub'>GitHub Package</a>
<div id='js-code'>the javascript</div>
</div>
<div id="the-explanation" style="width:52%" class='code-scroll'>
<div class='an-explantion'>16 - Arrays with One Type</div>
<div id='explanation-text'>
<pre title='Copy and paste the green code below into the console to run' class='console-runnable'>
func1 = (string_array) => string_array // array of strings
PRE_check_func1 = (string_array) => {
return type_czech.checkParam_type(string_array, ['strings'])
}
func1 = type_czech.linkUp(func1, PRE_check_func1)
func1(['pass', 'a-string']) // pass
func1(['fail', 12]) // fail - 12
</pre>
<pre title='Copy and paste the green code below into the console to run' class='console-runnable'>
func2 = (string_array_2) => string_array_2 // array of 2 strings
PRE_check_func2 = (string_array_2) => {
type_signature = ['string', 'string']
return type_czech.checkParam_type(string_array_2, type_signature)
}
func2 = type_czech.linkUp(func2, PRE_check_func2)
func2([ 'pass', 'two']) // pass
func2([ 'fail', 'two', 'three']) // fail - 3 elements
</pre>
<pre title='Copy and paste the green code below into the console to run' class='console-runnable'>
func3 = (arr_of_arr) => arr_of_arr // arrays of arrays
PRE_check_func3 = (arr_of_arr) => {
return type_czech.checkParam_type(arr_of_arr, ['arrays'])
}
func3 = type_czech.linkUp(func3, PRE_check_func3)
func3([ [], ['a'], [2], ['pass', 3] ]) // pass
func3([ [], [], [], 'fail' ]) // fail - not array
</pre>
<pre title='Copy and paste the green code below into the console to run'...