Click here to Skip to main content
14,662,170 members
Home » Discussions » JavaScript
   

JavaScript

 
SuggestionRe: Validate if my drop location is not empty using JS(HTML DnD API) Pin
Richard MacCutchan1-Feb-20 21:33
mveRichard MacCutchan1-Feb-20 21:33 
GeneralRe: Validate if my drop location is not empty using JS(HTML DnD API) Pin
Member 147327851-Feb-20 22:41
MemberMember 147327851-Feb-20 22:41 
AnswerRe: Validate if my drop location is not empty using JS(HTML DnD API) Pin
Richard Deeming3-Feb-20 0:53
mveRichard Deeming3-Feb-20 0:53 
GeneralRe: Validate if my drop location is not empty using JS(HTML DnD API) Pin
Nathan Minier3-Feb-20 1:10
professionalNathan Minier3-Feb-20 1:10 
AnswerRe: Validate if my drop location is not empty using JS(HTML DnD API) Pin
ZurdoDev3-Feb-20 2:20
mveZurdoDev3-Feb-20 2:20 
AnswerRe: Validate if my drop location is not empty using JS(HTML DnD API) Pin
jkirkerx5-Feb-20 12:40
professionaljkirkerx5-Feb-20 12:40 
QuestionPls help!javascript Noobie, Im getting if the average of the array is whole number, why does the method 2 doesn' work? Pin
Member 1472307521-Jan-20 16:36
MemberMember 1472307521-Jan-20 16:36 
AnswerRe: Pls help!javascript Noobie, Im getting if the average of the array is whole number, why does the method 2 doesn' work? Pin
Richard Deeming21-Jan-20 23:52
mveRichard Deeming21-Jan-20 23:52 
Because you're using two completely different calculations:

Method 1:
Sum up all of the items in the array. Divide the sum by the length of the array.
arr.reduce((accum, val) => accum + val) / arr.length

// Equivalent to:
var accum = arr[0];
for (var i = 1; i < arr.length; i++) {
    accum = accum + arr[i];
}

var result = accum / arr.length;

Method 2:
For each value in the array, add that value to the accumulator, and divide the intermediate result by the length of the array.
arr.reduce((accum, val) => (accum + val) / arr.length)

// Equivalent to:
var accum = arr[0];
for (var i = 1; i < arr.length; i++) {
    accum = accum + arr[i];
    accum = accum / arr.length;
}

var result = accum;

Step through both methods with a debugger, or write out the steps on a piece of paper, and it should be obvious why the second method is wrong.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

QuestionCompare the Triplets | Printing two values. Pin
Manish16918-Jan-20 20:53
MemberManish16918-Jan-20 20:53 
AnswerRe: Compare the Triplets | Printing two values. Pin
phil.o18-Jan-20 22:09
mvephil.o18-Jan-20 22:09 
QuestionHow I can close current tab in a browser window using JavaScript? Pin
Member 1471392612-Jan-20 2:40
MemberMember 1471392612-Jan-20 2:40 
AnswerRe: How I can close current tab in a browser window using JavaScript? Pin
Blikkies13-Jan-20 5:08
professionalBlikkies13-Jan-20 5:08 
GeneralRe: How I can close current tab in a browser window using JavaScript? Pin
Member 1471392613-Jan-20 5:16
MemberMember 1471392613-Jan-20 5:16 
QuestionRe: How I can close current tab in a browser window using JavaScript? Pin
ZurdoDev13-Jan-20 6:19
mveZurdoDev13-Jan-20 6:19 
AnswerRe: How I can close current tab in a browser window using JavaScript? Pin
Richard Deeming13-Jan-20 8:04
mveRichard Deeming13-Jan-20 8:04 
GeneralRe: How I can close current tab in a browser window using JavaScript? Pin
ZurdoDev13-Jan-20 8:27
mveZurdoDev13-Jan-20 8:27 
GeneralRe: How I can close current tab in a browser window using JavaScript? Pin
F-ES Sitecore13-Jan-20 22:24
mveF-ES Sitecore13-Jan-20 22:24 
GeneralRe: How I can close current tab in a browser window using JavaScript? Pin
Blikkies14-Jan-20 20:10
professionalBlikkies14-Jan-20 20:10 
QuestionJSON: How to insert URL in the child node? (Output is HTML file) Pin
TapCha910-Jan-20 1:02
MemberTapCha910-Jan-20 1:02 
AnswerRe: JSON: How to insert URL in the child node? (Output is HTML file) Pin
F-ES Sitecore10-Jan-20 1:36
mveF-ES Sitecore10-Jan-20 1:36 
QuestionGuys Please help me , How do I link this HTML with Css and Js properly? Pin
Member 147047841-Jan-20 19:46
MemberMember 147047841-Jan-20 19:46 
QuestionHow do you pause an animation? Pin
Marc Hede18-Dec-19 2:55
MemberMarc Hede18-Dec-19 2:55 
QuestionImages are not loading that are referenced in CSS Pin
simpledeveloper17-Dec-19 13:10
Membersimpledeveloper17-Dec-19 13:10 
AnswerRe: Images are not loading that are referenced in CSS Pin
Richard MacCutchan17-Dec-19 21:54
mveRichard MacCutchan17-Dec-19 21:54 
GeneralRe: Images are not loading that are referenced in CSS Pin
simpledeveloper18-Dec-19 7:34
Membersimpledeveloper18-Dec-19 7:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.