The RMS (Root mean square) value of a distribution is the square root of the mean of the squares of the elements. The formula to find RMS value are given below:
To calculate RMS value of an array, first need to square all the elements in the array. Then, take the mean of those squared value by summing it and dividing it by the number of the elements and finally take the square root of that number.
Now the above script converted into single line script. To write the above script into single line, first convert the arr to another array of squares using Map function which returns an array. Now apply reduce on that array directly which will return a single value (sum of all the squares). Sum of square of number divided by number of elements and get the square root. It will produce RMS value.
Benefits Of Writing An One-line Functions
The less code will require less memory, so it will take less time for any Web Browser to load the script with less memory. Further, the browser renders the WebPage by executing the code line-by-line, so any operation on website involving One-line functions will respond much quickly as compared to the normal functions.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer Geeks Classes Live