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 354 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
Most people can do absolutely awe-inspiring things,” he said. “Sometimes they just need a little nudge.