Complex Arrow Function Example

Here is an example using a Complex or Higher Order arrow function, which slightly reduces the amount of code lines used. This should return the square root of all positive integers passed into it.


const realNumberArray = [9, 24, 168, -73, 4.5, 6.9, 1345, -2];

function run_function(arr) {
  const squaredIntegers = arr.filter( (rnum) => rnum > 0 && rnum % parseInt(rnum) === 0 ).map( (rnum) => Math.pow(rnum, 2) );
  var my_result = squaredIntegers;
  return my_result;

// this is a common function just to write the content into the result div
function write_result(result) {
  var result_html = document.getElementById("result");
  result_html.innerHTML = result;


<div id='result' class='mb-3 alert alert-primary'>..</div>
<button onclick='run_function(realNumberArray);' class='btn btn-primary mb-1'>Run Function</button>

Working Result


External Link for Complex Arrow Function Example

Other Items in javascript
Page Views

This page has been viewed 258 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
You want to be the best, you MUST put the long yards in! Nothing comes easy in life so stop wishing and start DOING! So many people would rather bitch and moan than help themselves. Dont be one of those negative drainers, start today, make a small change and keep going forwards with this attitude!