Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
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 ...
wittgenstein's user avatar
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 ...
WyreZ's user avatar
  • 31
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 ...
Gibberish's user avatar
  • 109
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 ...
uber's user avatar
  • 261
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: ...
fruitlessartery's user avatar
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 ...
Álvaro's user avatar
  • 177
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 ...
Álvaro's user avatar
  • 177
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 ...
Álvaro's user avatar
  • 177
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 ...
Joji's user avatar
  • 325
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: ...
Ryan's user avatar
  • 51
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: ...
gremo's user avatar
  • 439
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 ...
Nɪsʜᴀɴᴛʜ ॐ's user avatar
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 ...
Will Pierce's user avatar
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 ...
Nelo's user avatar
  • 135
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 ...
Nelo's user avatar
  • 135
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 ...
Nɪsʜᴀɴᴛʜ ॐ's user avatar
13 votes
5 answers
3k views

Vue.js search functionality

In my BlogList.vue component I made a search input field: ...
meez's user avatar
  • 241
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 ...
Gourav Makhija's user avatar
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. ...
Linny's user avatar
  • 10.3k
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} * ...
Jim's user avatar
  • 41
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 ...
Tony's user avatar
  • 295
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 ...
Jelefra's user avatar
  • 133
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: ...
ealef's user avatar
  • 153
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: ...
MadHatter's user avatar
  • 837
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) ...
Igor Soloydenko's user avatar
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 ...
ReeseyCup's user avatar
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 ...
xkeshav's user avatar
  • 131
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 ...
redOctober13's user avatar
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? ...
qw3n's user avatar
  • 153
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 ...
msanford's user avatar
  • 391
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). ...
user1934212's user avatar
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 ...
Gavin Hughes's user avatar
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 ...
msanford's user avatar
  • 391
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 ...
Phrancis's user avatar
  • 20.4k
1 vote
1 answer
68 views

Grouping sub-arrays with nonidentical items

I have a 2D array like ...
Redu's user avatar
  • 906
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" ...
misterioss's user avatar
1 vote
1 answer
52 views

Convert big collection into simple array

Is there a better way to do this? ...
jdsninja's user avatar
  • 177
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. ...
roger's user avatar
  • 115
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 ...
Jose Hermosilla Rodrigo's user avatar
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 ...
Redu's user avatar
  • 906
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: ...
Chris's user avatar
  • 153