how do i test this javascript function showing it working would be amazing!!!! the function and instructions are as follows function repeatf(f,n) { if(n


how do i test this javascript function


showing it working would be amazing!!!!


the function and instructions are as follows


function repeatf(f,n) {
    if(n<=0) {return="">
    var result= new Array(n);
    for(var i=0; i
        result[i]=  f();
    }
    return result;
}


repeatf( f, n )

This function accepts a function of no arguments ( f ) and an integer number ( n ). The function must return a list that contains the results of n executions of f. If n is non-positive this function must return the empty list.


Examples




  • repeatf( () => { return "cow"; } , 3 ) => [ "cow", "cow", "cow" ]

  • repeatf( function() { return 3; }, 2 ) => [ 3, 3 ]

  • repeatf( Math.random, 3 ) => [ , , ]







Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here