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.

Demo

JS


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;
  write_result(my_result);
  console.log(my_result);
  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;
}

HTML

<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 28 times.

Search Code
Search Code by entering your search text above.
Welcome

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.

❤👩‍💻🕹