Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using JavaScript. Use the Following functions create calls to each of the functi

ID: 3848186 • Letter: U

Question

using JavaScript. Use the Following functions create calls to each of the functions then display the results. use the following data for arguments:

e. [-10, 25, 0]

f. [10, 0, 0, 0, false, true, 0, 0]

g. "Adrian Tillman was here", "a"

h. [1, 2, 3,5,7, 10, 12, 13, 15, 20]

Functions:

E:

def median(lst):

sortedLst = sorted(lst)

lstLen = len(lst)

index = (lstLen - 1) // 2

if (lstLen % 2):

return sortedLst[index]

else:

return (sortedLst[index] + sortedLst[index + 1])/2.0

F:

def numberOfZeroes(lst):

count=0

for val in lst:

if val==0:

count+=1

return count

G:

def cntOccurrences(string,char):

count=0

for ch in string:

if ch==char:

count+=1

return count

H:

def isPrime(lst):

prime_lst=[]

for val in lst:

if val > 1:

for i in range(2,val):

if (val % i) == 0:

break

else:

if val not in prime_lst:

prime_lst.append(val)

return prime_lstreturn Math.floor(Math.random() * (max - min + 1)) + min;

}

Explanation / Answer

I am providing you the solution of e,f and g.I am not getting exactly what we have to return in function isPrime() as it is returning two values which is conceptually not possible.

<script>

function median(lst)
{
var sortedLst=sort(lst);
var lstLen=sortedLst.length;
var index=(lstLen-1)/2;
if(lstLen%2==0)
return sortedLst[index];
else
return (sortedLst[index]+sortedLst[index+1])/2.0;
}
function numberOfZeroes(lst)
{
var i;
var count=0;
for(i=0;i<lst.length;i++)
{
if(lst[i]==0)
count++;
}
return count;
}
function cntOccurance(str,ch)
{
var count=0;
var i;
for(i=0;i<str.length;i++)
{
if(str.charAt(i)==ch)
count++;
}
return count;
}


var e=[-10, 25, 0];
var f=[10, 0, 0, 0, false, true, 0, 0];
var g="Adrian Tillman was here";
var c='a';
var res1=median(e);
document.write("Median="+res1+"<br/>");
var res2=numberOfZeroes(f);
document.write("Number Of Zeroes="+res2+"<br/");
var res3=cntOccurances(g,c);
document.write("Number Of character"+c+" in string "+g+" = "+res2+"<br/");
</script>