Skip to content

Tag: javascript

How to write this function with forEach?

I am trying to group the people by their age and as you can see, my code works with the reduce method. I managed to get this working but now I want to do the same with forEach method. Here’s my code: Answer Reduce accepts initial value that you update each iteration and return. So if you wish to use

Swapping array with alternative numbers

In an array take alternate numbers and swap them. Put it again in the place of array again e.g., arr = [8,7,4,6,9,3,2,1] newarr= [8,1,4,3,9,6,2,7] The Code which I tried is below one This is not the correct way to proceed. Answer When you consider every odd indexed element to be alternate –

Using Javascript libraries in Curity scripts

I’m getting to grips with Curity, and it looks very promising, but I need to replicate a weird hashing function from a legacy system. The built-in context class passed in to a credential transformation procedure does not include the algorithms I need, so I want to use the crypto-js library. Unfortunatel…

Filter html elements based on data attribute

I have the following html structure And what I want to do is to get the count of child divs that contains different data attribute. For example, I’m trying this: But that code is returning 6 and what I want to retrieve is 4, based on the different data-customId. So my question is, how can I add a filter…