Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to rewrite this ramda.js code in vanilla JS

I am removing ramda from some code I’ve inherited as part of an effort to reduce the JavaScript size. But I’m stuck with the below because this line really baffles me as it apparently doesn’t operate on any object.

var iterate = R.addIndex(R.forEach);

The relevant code looks like this:

var lis = $(el).find("ul.navbar-nav:not(.navbar-right) > li:not(.nav-more)");

var iterate = R.addIndex(R.forEach);

iterate(function(li) {
    // Other code

}, lis);

How can I write it in vanilla JS?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Convert the object to a standard array using Array.from() and then you JS Array.forEach():

const iterate = (fn, o) => Array.from(o).forEach(fn)

iterate(function(li) {
    // Other code

}, lis);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading