All Questions
Tagged with arrayjavascript
398 questions
43votes
3answers
44kviews
Partitioning an array based on a condition in Javascript
Using the array.filter function, I can efficiently pull out all elements that do or do not meet a condition: ...
26votes
2answers
133kviews
Extract numbers from a string-Javascript
Consider the following string in javascript: var string="border-radius:90px 20px 30px 40px"; I want to extract the 4 numbers from that string and store them in ...
23votes
3answers
141kviews
17votes
4answers
10kviews
Cropping a message using array splits
I am trying to write a simple function to crop a given message to a specific length but at the same time not to cut the words in between and no trailing spaces in the end. Example: Input String: ...
16votes
6answers
53kviews
Find common elements in a list of arrays
I need to find the common elements present in all the given arrays. All the arrays are present in another array. I have come up with this solution and it's working. I tried to remove the usage of <...
14votes
4answers
41kviews
Writing a function to add or modify an existing object inside an array
I have an array of objects. Each object has two properties, id and quantity. I wrote a function to add an object to the array. ...
14votes
1answer
10kviews
Implement numbering scheme like A,B,C... AA,AB,... AAA..., similar to converting a number to radix26
I want to implement numbering scheme like Microsoft Word uses for numbering. first one gets = A,next is B, next is C, .... then AA, then AB,....and so on. as shown below ...
14votes
2answers
20kviews
Rotating array members
I had a situation when I needed to move all array elements in circular fashion. When I say this, I mean: 0 1 2 3 1 2 3 0 2 3 0 1 3 0 1 2 The array: ...
13votes
5answers
3kviews
Vue.js search functionality
In my BlogList.vue component I made a search input field: ...
12votes
7answers
31kviews
Given an array of integers, return all pairs that add up to 100
I was recently given this programming challenge on an interview, and I decided to use javascript to solve it. I did, but I'm not happy with my implementation. I can't help thinking there must be a ...
12votes
1answer
621views
Heaviest Stone algorithm time complexity
I implemented the heaviest stone algorithm, but I am not sure about its time complexity. I'm doing sort which is O(nlogn), but it' inside a while loop. Problem: We have a collection of stones, each ...
11votes
5answers
5kviews
Check if three arrays contains the same element
Do 3 arrays contain a common element, if they contain output it. For example: [1,2,3], [2,3], [2,4] -> answer = 2 ...
11votes
4answers
3kviews
Restructuring JSON to create a new JSON where properties are grouped according to similar values
I have a JSON structure in the following example format: ...
11votes
3answers
10kviews
Sum all numbers in a range
I have implemented the "Sum All Numbers in a Range" challenge from Free Code Camp quoted below. The code works like a charm, but I don't think it's idiomatic. The challenge hints imply I ...
11votes
3answers
10kviews
Displaying random quotes from an array
Is there anything that I could have done better in this code? ...