Skip to content
Advertisement

Tag: arrays

Index Values SumUp to Total

I am trying to improve in my Problem Solving Skills and would love to get some explanation on what it is that I am doing wrong or if I can get a hand in the right direction. My code below is what I am stuck on. My problem, I am trying to check within the array if it contains any

Reduce throws “NaN” in JavaScript?

I am trying to sum items in array. While searching Google and Stack Overflow I found that reduce is a good way of summing an array items. But, when there isn’t any key value pair reduce throws error as “Nah”, so how to deal with it? My array exam: So from above, I need to calculate all the key values

Fill array with prompt in JavaScript and use push method

I am learning arrays in JavaScript and I am using the foreach with the push method. The following code is working as its supposed to: But I want to replicate this with a prompt, instead of hard coding the values in the array. And end the prompt with a 0. The code I attempted is the following, but the variables

Recursively Search in Array with a For Loop

I know there are better ways to search an array, but I really want to understand how to return when the value is found in a recursive call. Logging when found isn’t a problem, but I can’t seem to make this return true when found. The problem is basic. Fully search multi-dimensional array for a value and return true if

Compare arrays of Errors in Chai

I have a validator method that returns an array with Errors. I want to create a unit test that compares this errors, but I can’t use expect(fn).to.throw since I don’t throw the errors, just return them. This is my approach but I get AssertionError: expected [ Array(2) ] to have the same members as [ Array(2) ] Previously we used

Break array of objects into 2dimensional array

I need to break an array of objects into a 2-dimensional array where 1-dimensional arrays would consist of objects which have their attributes ‘for’ and ‘to’ being not overlapping intervals. Example: Given array arr1 I wish to receive arr2 How it should work: We loop through the arr1. Object1 should be put into the first 1-dimensional array in arr2 by

Advertisement