All Questions
Tagged with ecmascript-6 array
41
questions
1
vote
1
answer
130
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
82
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
197
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
564
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
46
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
759
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
347
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
172
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
66
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
49
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
123
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
375
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 ...
3
votes
1
answer
54
views
Iterating an Array Object & Assigning the Attributes Values to those that Match the Condition
Is there any approaches to reduce the below coding snippet in Angular 2+ with few lines of code by making use of ECMA Script or by some other ways
...
13
votes
5
answers
3k
views
Vue.js search functionality
In my BlogList.vue component I made a search input field:
...
0
votes
1
answer
83
views
How to simplify this ES6 Array code
I'm just wondering Is there any ways I could simplify the following code without making it too difficult:
Actually I want to extract specific year data from content node based on lastNumberOfYears ...
2
votes
1
answer
76
views
Rewrite of Array.join
While rewriting Array so I can practice my javascript, I looked at my implementation of .join(). It seems a little clunky to me.
...
4
votes
2
answers
127
views
An ES6 array of numbers - Double last number, delete the first number
I'm writing a JavaScript function for an array, based on a geographic sequence. \$[1, 2, 4, 8, 16]\$, etc.
This function needs to populate the next number in the sequence
$$item_n = item_{n-1} * ...
1
vote
2
answers
58
views
Combining arbitrary number of lists inside json
I have some JSON where each key stores an array, and I need to combine all those arrays into a single array. My current solution doesn't seem the most friendly to review, but without ...
2
votes
1
answer
119
views
Manipulating arrays to extract unique objects and count occurrences
The data describes cycling activities (key1) and chunks of them (key2). In total there are around 1,000 ...
4
votes
4
answers
160
views
Filtering a name Array in JavaScript
I was wondering if there is a better, more elegant way to write the following JavaScript code block:
...
1
vote
1
answer
839
views
JavaScript Determine if Array has Almost Increasing Sequence
A coding challenge on a website says to determine if an array would have an increasing sequence if one element were removed from that array.
Here is the function:
...
6
votes
1
answer
1k
views
Multiple stacks implemented via a linked lists on top of single fixed-size array
Problem Statement
Originally, the problem is defined in the book as following:
Describe how you could use a single array to implement three stacks. — Cracking the Coding Interview (6th edition)
...
1
vote
2
answers
202
views
Manipulating an ES6 static class property that is an array
I've been trying to find a way to create static properties in ES6 classes and have found a solution with the help of various Stack Overflow answers (namely this one and this one).
However, I also ...
0
votes
1
answer
35
views
Merging array entries referenced by indexes in another array
I have one question list (q_arr) and the user can either skip or attempt that question. In the end of last question, I display all question with their selected ...
5
votes
3
answers
101
views
Aggregate summary counts for an array of error objects
I'm doing some refactoring of someone else's code, and just want a second opinion, because of course I think my work makes it better, but some validation (or correction) would be helpful.
Starting ...
5
votes
2
answers
2k
views
If non-array property exists convert it to one and push new value
Is there a simpler/shorter/better way to do this?
...
5
votes
3
answers
3k
views
Sorting an array of objects by a property which may be missing
Problem
I am sorting an array of objects. Each element may have a property called reference or it may be undefined. When ...
1
vote
2
answers
146
views
SQL-style join on arrays using ECMA6
I have a code snippet which performs an SQL-style join on objects in two arrays based on a specific field (in the code below, .id).
...
10
votes
2
answers
684
views
Array duplicate removal for duplicates exceeding `N`-number
I recently encountered a front-end interview coding challenge question that required one to create a function which returned an array that excluded numbers that occurred more than ...
3
votes
1
answer
50
views
Create several homogeneous arrays from a larger heterogenous array efficiently
I have a list of aircraft returned from a REST call which describes the status of each aircraft. In order to make the UI templating simpler, this single list is split into four homogeneous lists in ...
3
votes
1
answer
5k
views
Codewars "Consecutive strings" kata
The challenge description is as follows:
You are given an array strarr of strings and an integer k. Your task is to return the ...
1
vote
1
answer
68
views
Grouping sub-arrays with nonidentical items
I have a 2D array like
...
3
votes
2
answers
66
views
Calculate amount of elements in collection by property
I was given this task: Calculate amount of elements in collection by property: "name"
...
1
vote
1
answer
52
views
Convert big collection into simple array
Is there a better way to do this?
...
0
votes
4
answers
16k
views
Move array element to the first position
I wrote an update() function to make an entry the first element in an array.
...
3
votes
1
answer
1k
views
Filling Array with Alphanumeric values
I've done a function that does the following :
It takes an argument length that it will be the length of the result array.
The Array should start with alphabet ...
4
votes
3
answers
25k
views
"Prev" / "Next" buttons for a circular list
I have an array of strings and on click of the "NEXT" button it displays the next array item in a <p> tag while on click of the "PREV" button it displays the ...
5
votes
1
answer
3k
views
Generating an HTML table with colspan and rowspan from a one-dimensional array
I will be given the following input:
...