All Questions
Tagged with array ecmascript-6
41 questions
1
vote
1
answer
140
views
Transform an array into object and set index for an unique key in javascript
I have a method that merges keys and indexes from an array into an object.
I'm stuck with ways to compress this method, and I don't know what I can do to make it simpler.
Goal
get an array of objects ...
3
votes
1
answer
83
views
Function that sorts nestedArray[][]'s
I'm fairly new to coding and am trying to learn more about best practices. I wanted to have an nestedArray of objectArrays, and I wanted to be able to sort the elements in each objectArray based on ...
3
votes
1
answer
204
views
Randomly set styles with JavaScript
I have created a function which randomly sets styles using CSS selectors. Right now it returns a random item from an array. The program also works with shorthand properties (such as ...
4
votes
2
answers
575
views
File naming (two files cannot have equal names)
This is a challenge I completed at CodeSignal.
You are given an array of desired filenames in the order of their creation. Since two files cannot have equal names, the one which comes later will have ...
11
votes
4
answers
3k
views
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:
...
2
votes
2
answers
47
views
Combine data from array of objects
I got this data structure and I am checking to see which properties are true, then I am adding the key for all the properties that are true to that object on a new ...
1
vote
2
answers
767
views
Recursively find data in array of objects
On this script I look up properties in an array of objects. There is an original array of strings list to get the objects that match the ...
1
vote
1
answer
4k
views
Add / Overwrite an object in an array
I am trying to overwrite an object in an array if the title property exists, otherwise just push it to the array. I found two approaches and I wonder which one is ...
6
votes
1
answer
357
views
JavaScript: A drawing program in OOP
I made a little drawing program in OOP.
The game consists of a canvas which is basically a 2d array where the user can draw various shapes on it. There can be multiple shapes overlapped on top of each ...
5
votes
1
answer
182
views
Generate all partitions of a set of items
Here are the items:
var item = ['a', 'b', 'c', 'd'];
Desired output:
...
0
votes
1
answer
67
views
Avoid the object/array check and treat the return value the same way with JavaScript spread operator?
I'm trying to implement a function (a template-helper function) which provides a simple merge-like functionality for both arrays and objects. The two functions are basically looks identical:
...
1
vote
1
answer
53
views
Filtering Array Based on Element Values
Required to splice specific element value in an array based on the condition.
Both the below code does the same job and yields the correct results. But couldn't figure out how to reduce coding ...
5
votes
3
answers
140
views
Removing unneeded objects from an array before rendering
I'm making a function that adds a new object to an array and removes the oldest if it has reached a specific length. Click the button in the example below. All objects are drawn until its array ...
4
votes
1
answer
384
views
Extract string list as array from an array of objects
Having the following array of objects of ingredients used by cooks
...
8
votes
3
answers
2k
views
Javascript split array into n subarrays, size of chunks don't matter
NOTE: This post was moved from stackoverflow as codereview.stackexchange is a better place to discuss the performance of this code problem/solution.
I want to split ...