Questions tagged [javascript]

ECMAScript or ES (commonly referred to as JavaScript) is primarily used for scripting web-pages but also has several embedded forms as stand-alone interpreters or JIT compilers. Use this tag for questions regarding all versions of ES up to the current ES8 and its dialects / implementations: JavaScript, JScript, etc., excluding ActionScript.

Filter by
Sorted by
Tagged with
0
votes
2answers
22 views

Finding the objects with the cheapest seats

i have the following json object ...
0
votes
0answers
7 views

Implementing a react component Treeview

Today after watching a getting started course about React I tried to code my very first React component, a treeview as title says. It does work, but as a newbie I know there are many improvement that ...
4
votes
0answers
21 views

JS deep merging of objects- removing empty keys

I've written a helper for combining objects (deep merge). It works, and is flexible to add options (like uniq and replace). ...
1
vote
1answer
33 views

Javascript calculation function

I use this function to to do some calculations based on 4 select inputs and one number input, I don't have experience in Js, I did some research in w3schools then I ended up with the function below. ...
4
votes
1answer
41 views

Work order spatial query

I have a script in a Work Order Management System (Maximo) that performs a spatial query. Details: Takes the X&Y coordinates of a work order in Maximo Generates a URL from the coordinates (...
3
votes
2answers
52 views

Sort, slice and rebuild new object with array data

I'm using the matomo reports api to pull out some data in js. For some charts, I'm in the need to sort the array data based on inner property value ("val"), further to get only the 3 highest (Hong ...
0
votes
0answers
16 views

Sorting, filtering and searching a list using jQuery

This is my first time writing so much jQuery, and because of the amount of content on the page, I get a lot of the following console warning in Google Developer Tools as I'm changing filters: [...
3
votes
1answer
36 views

How to properly get values from multidimensional object

Output should be an object ({cal: val}), with soonest possible time throughout all calendars recommended times from the data. My question is: is this approach over complicated and if so, what should ...
-4
votes
0answers
19 views

I need to add a menu item into following script [on hold]

Basically this script generates right click menu on the website and I need to add one more item to it. The item I want to add, would only be visible, when right click is performed on a file. UL ...
1
vote
0answers
37 views

Find minimum number of rooms required

Problem statement is as follows Given an array of time intervals (start, end) for classroom lectures (possibly overlapping), find the minimum number of rooms required. For example, given [(30, ...
-4
votes
1answer
29 views

I need to modify this code to produce the desired output [on hold]

I need to modify the function to return a new array of names of the people who are 16 or older. ...
3
votes
1answer
77 views

Summing same index values in 2D arrays in javascript

After solving a problem, I came to this conclusion. ...
0
votes
0answers
20 views

Multiple animation control using Vanilla JS ES6

What I'm doing Divide members into five section, and apply animation for each member to reveal at first. When I click the section, it is expanded to whole viewport and introduce detail about ...
4
votes
4answers
81 views

MergeSort in Javascript

I implemented the following mergesort algorithm in JavaScript, but I want to know your opinion about if is possible to do better than this. ...
3
votes
2answers
42 views

JavaScript number obfuscater

I got inspired to do this after seeing this repo containing a bunch of weird syntactical quirks in JS, namely this example called "It's a fail!". The example was essentially the following: You ...
-2
votes
0answers
14 views

Algorithmic Performance: Solution Analysis of JS Functions [closed]

Good Day! I'm shaky on algorithmic performance analysis (Big O time and space complexity) and was wondering if the code I wrote has the proper time and space complexity. Also are there any ways to ...
1
vote
1answer
25 views

Create plain object from URLSearchParams

Is there a shorter / cleaner way of creating a plain object from URLSearchParams than this: ...
4
votes
2answers
92 views

Dynamically add/remove fields on input

The following code allows users to enter multiple optional quantity fields after first filling in a value of the current quantity input. If the input field contains a value it will then display the ...
1
vote
1answer
58 views

Is this a good approach for AJAX using vanilla JS and PHP?

I'm looking for a good approach to AJAX communication using only pure JS and PHP. I would like it to be as safe as possible and compatible with most modern browsers and IE 10+. I did some research and ...
2
votes
0answers
32 views

Clean code: Permission with middleware

In my example, I have four models: User, Company, Project, and Plant (though my project technically has more: Plant, Job, Team, etc.). ...
1
vote
1answer
39 views

Emulating the pipe operator in javascript in a readable way

In this article I found this quite elegant looking Elixir code: ...
0
votes
2answers
89 views

Driver for sensor payload decoder

I have written a driver in JavaScript that decodes the payload of the sensor which is hexadecimal encoded. It receives the payload and the port details to the pre-defined function 'decode' which is ...
3
votes
2answers
80 views

Descending selection sort in JavaScript

I wrote a simple sort algorithm in JavaScript, but code climate is complaining its complexity being too high (currently sitting on 6 instead of 5, which is code climate wants). I personally cannot ...
4
votes
1answer
52 views

Event triggers for animations using vanilla ES6

I'm new to JS and wanna know right code style or approach to cod Vanilla JS using ES6. To practice this, I'm using ESLint JS code-style of AirBnb and referencing clean-code-javascript repo. However, I ...
0
votes
0answers
23 views

Server Design with GraphQL.Js

To learn graphql I'm creating a server for queries to a local postgres cluster. The pg cluster is populated with sample data from postgresqltutorial.com and I wanted to use GraphQL.Js instead of ...
3
votes
1answer
57 views

“Real world” JSON transformation using Node.js

Background I transformed a non-trivial JSON response that uses arrays into a nested object eliminating some of the original properties inserting a new summary property that is a unique list of ...
0
votes
0answers
34 views

How to filter URL from the array list based on the string name with regExp?

The solution found to filtering pathname with customising current normalizeTme() function. For sure it is not the ideal way of ...
1
vote
1answer
70 views

Constructor function for persons with hobbies

I'm trying to write a constructor function that generates instances of a user. One of the properties of the user class is an array of the user's hobbies. I'd like ...
3
votes
0answers
37 views

JS PHP insert data in database - is it secure enough?

I'm working on a webapp and I'm using js/php (php and jquery latest versions). Is there anything I should do to improve security? I'm not super worried about safety as the current users are using a ...
0
votes
0answers
22 views

Nested inner function and naked code blocks in JavaScript

The following code is called when the user selects a chapter from a book and populates a table with the list of all classes that are mentioned in that chapter. I want to maximize the ...
1
vote
0answers
40 views

Javascript + php system for reusable HTML templates

I have many pieces of HTML code that are used in many parts of the website (controlled by javascript), like edit forms and dialogs. Instead of include-ing the html ...
6
votes
2answers
491 views

Javascript - Find a deepest node in a binary tree

Problem Statement Given the root of a binary tree, return a deepest node. For example, in the following tree, return d. a / \ b c / d My ...
3
votes
1answer
54 views

Date format function in JavaScript

How can I improve the date format function. I have written in javascript (ES5/ES6)? This code is just a part of an exercise. ...
2
votes
0answers
31 views

React-auto-height

I created a react-auto-height library: A React component that animates height: auto children when their content is changed, using CSS transitions. It started ...
3
votes
1answer
44 views

Class diagram of Tic-Tac-Toe Game

I wrote a basic tic toe game. See, https://jsfiddle.net/shai1436/Lgy1u84s/4/ I am not satisfied with the way I have designed classes and how I have implemented the undo feature. Please suggest ...
2
votes
0answers
49 views

Find Single Element in a Sorted Array, from LeetCode

The problem quoted: https://leetcode.com/problems/single-element-in-a-sorted-array/ Given a sorted array consisting of only integers where every element appears exactly twice except for one element ...
2
votes
0answers
28 views

Simple landing page with a countdown timer and automatic slideshow with HTML,CSS,JS

Does this code follow common best practices? I tried to keep the code simple and straight forward adding comments and spacing everything to be readable. My main concern is there a common practice ...
1
vote
1answer
31 views

Middlewares with Route definition or Routes with Middleware definition

I am currently working on an Node based Express application. I have found Express's middlewares approach quite pleasing however, we all run in scenarios where a certain route or routes don't need a ...
3
votes
2answers
44 views

Filtering an object JS

I'm making a news aggregator using newsAPI, and have everything working - to begin with. But was wondering if the code I use to filter through an object can be made more efficient - meaning fewer ...
1
vote
0answers
34 views

Optimizing Node MySQL Query for CPU Utilization

I am working on a NodeJS port listener code that listens to a particular TCP port on the server. The obtaining the data from the port, the data is split using a delimited (for instance comma ...
4
votes
2answers
62 views

An Express route, which renders a page, and makes use of socket.io

This is the code for a basic endpoint in my express app routes folder. This firstly renders a page, and then on a continuous loop, renders information about some random "Breaking Bad" character. The ...
1
vote
1answer
45 views

Getting initial values of non-primitive types from another Javascript file? [closed]

I have a file where I keep some initial values for some form fields base on field type. Some of them are primitive values, like '' or 0 or false but some of them ...
4
votes
1answer
60 views

Finding optimal mapping patterns that transform relational data into a linear format

I'm trying to upgrade my javascript to be more functional. I have used function composition and curry successful on less complicated code but i'm now running into a point where i'm not sure on how to ...
4
votes
1answer
35 views

Responsive, scrollable sidenav for old browsers

The following code has been tested on the latest chromium, on Opera Mini, on Safari for IOS 7 and finally, on the default web browser on android 2.3.3. As you may already know, the CSS ...
1
vote
1answer
26 views

join method inside axios call

I am doing a join in the axios call. since doing two different api calls. for performance is this the good way. or do I need to use async await and then do join. providing code snippet below ...
4
votes
2answers
43 views

Extract lines under the specified heading

I wrote the following working code, which I just can't stomach: ...
2
votes
1answer
67 views

Sum of all possible concatenations of array values

Given an array of non-negative integers, we need to find the sum of concatenation of elements in the array. For example - given [11, 22] the result should be - 6666 i.e., 11 + 11 = 1111 11 + 22 = ...
1
vote
0answers
36 views

Javascript Widget Embed Code

I have developed the following javascript code for creating "widgets" that a third party site can paste onto their page and load content from our web application. Everything is working, and I am in ...
1
vote
1answer
43 views

Reverse a Linked List in place

I am solving some programming challenges for learning Javascript. The challenge I chose is: Given the head of a singly linked list, reverse it in-place. Here is my implementation in JS ...
4
votes
1answer
44 views

Function to create URL relative to a configured base URL

I have written this function to create a URL: ...