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
4
votes
2answers
42 views

Function invocation every second time

Recently I got test task at the project, it is fairly simple: ...
0
votes
0answers
7 views

Simple react app to fetch and display data

This is my first react app and it was for a job interview challenge. The app is really simple and it works, but although I don't think I'm gonna get it, could I have some feedback about what is wrong ...
1
vote
0answers
24 views

Toggling the background color of a page using JavaScript closures

This question is to see if I can get some input on the "design pattern" I tried to implement here. I'm just learning about closure in JavaScript and I think I'm starting to get it. I'm wondering if ...
6
votes
1answer
72 views

Given a string containing just parentheses, determine if the input string is valid

The task is taken from leetcode Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: ...
2
votes
0answers
25 views

Pure (almost) CSS Masonry

I developed this CSS Masonry. It works with a CSS grid with grid-auto-rows: 1px. There is a JS ...
2
votes
0answers
599 views

Deepest pit of an array

Following is based on a problem description from a Codility test, as a task in an interview. DeepestPit - problem description A non-empty zero-indexed array B ...
0
votes
0answers
21 views

delete forms which are displayed as images [on hold]

I have a code where I create over a form, images which are supposed to be other forms which can be edited. That's the code how I create them: ...
2
votes
1answer
36 views

ReactJS Calling an API and rendering results

I am currently learning JS Frameworks, right now exploring React and wanted to make sure I keep everything in order, as in: the logic of working with React, code quality, any shortcomings, good/bad ...
-1
votes
0answers
25 views

Exact same code but there's an error? [on hold]

I've been following this video:https://www.youtube.com/watch?v=YXZX_6RfHjk For some reason my code for the javascript portion is this: ...
5
votes
0answers
22 views

Vanilla Javascript: Chained AJAX request

I'd be grateful for a review of my AJAX request. If I have taken the correct approach here and especially any security concerns! I am creating a Purchase Order system for my manager (as part of an ...
3
votes
1answer
34 views

Ajax function with a callback

I have Ajax function with a callback which fetches all the Patient data however I have some perfomance issues and trying to figure out what it might be, does anyone have idea? That's my Code ...
4
votes
1answer
69 views

<select multiple> with dropdown

I wanted to use <select multiple> but was annoyed by the poor design on desktops which is why I created a version with dropdown: ...
3
votes
1answer
35 views

JavaScript function to categorize data by their “styles” attribute, and store the key-“unicode” pair

I have a JavaScript function to categorize data by their "styles" attribute, and store the key-"unicode" pair. Here's my current code: ...
7
votes
1answer
76 views

Quicksort in JavaScript assuming an immutable array

Update: further succinct versions below (inspired by Haskell) Quick sort in JS assuming an immutable array: ...
2
votes
1answer
20 views

Throttle implementation using pure JavaScript adding and removing event listener

I am trying to implement throttle function in vanilla JavaScript. I have seen other implementations on the web, but the way I have implemented it is more understandable for myself. I was wondering if ...
0
votes
0answers
16 views

filter a select tag by an input able to find middle characters [on hold]

i have a select with dynamic options and values, and an input so user can type inside the input and select values get limited to those that has typed characters. i found this: similar question link ...
-1
votes
2answers
28 views

Please help refactor these jQuery code selectors for checked and unchecked checkboxes [on hold]

As you can see below, the following code has redundancies: ...
3
votes
5answers
7k views

Printing staircase revisited

What can be more elegant ways to solve the given problem. # ## ### #### Code: ...
6
votes
1answer
708 views

Datepickers for departure and return dates

I have to two datepickers. I want achieve the following functionality: the return date cannot be selected before the selected departure date and the departure date cannot be after the selected return ...
3
votes
4answers
3k views

Function to find the shortest word in an array, where not every element is a string

I wrote a solution for a codeCamp exercise: Write a function called findShortestWordAmongMixedElements. Given an array, ...
1
vote
1answer
30 views

Showing a unique result based on options selected

I created a simple quiz in HTML/CSS and plain Javascript. There are three questions with two options each, so there are eight possible combinations of answers, and therefore results. You can only pick ...
1
vote
1answer
33 views

Dynamically inserting html from external file and updating the database

I need some suggestions on how to approach this. I want to allow users to create sections of website. The code so far is working but since I am new to back-end I feel like there is better, more ...
9
votes
2answers
86 views

Fetching movie data using jQuery

Requirements Display movie datas inside all tags that have the class movie_list Make an ajax call for fetching movie datas Fill loading text before fetch data If any error occurs during loading, the ...
2
votes
0answers
72 views

Angular 1 CSS Encapsulation

I am trying to get a good clean way to do CSS Encapsulation in Angular JS. The main goal of this is to use isolated components. This is what I have come up with so far. The method I am using is ...
3
votes
1answer
43 views

Pivotting SQL Table Response to JSON in JavaScript

Issue Our API returns two formats JSON and this SQL table format. I'm not sure what it is truly called so I'll give a few examples below. Like all API responses, it can be a list or a single response ...
-5
votes
0answers
34 views

Find the most occuring string in array with their required level [on hold]

input = ['A','A','B','C','C','A','A','D','D','D','D','D','E','A','A'] requiredElements = 3 output = ['A','D','C']. it is possible to change the required elements ...
6
votes
1answer
183 views

Atomic elements selector engine

I've written a DOM element selector engine that I'm really quite happy with, and I'd love to hear some opinions on it from my fellow JavaScripters :D It's called Atomic, and I've got a repository for ...
3
votes
1answer
416 views

Calling a Luhn check function when a credit card field changes

I feel like I should not be duplicating the code to gather the credit card number, but I am not sure how best to do it. Any suggestions? ...
8
votes
6answers
5k views

Best practice and alternatives for string manipulation with an emphasis on readability

As a personal habit I generally prefer to use string replace and format methods, along with string "patterns", in lieu of string ...
2
votes
1answer
47 views

Filter list items

I have a list of items I pull from SharePoint and want to filter them in my custom list view page. So my function works exactly how I want, but it seems messy and I'm hoping someone could point me to ...
2
votes
1answer
24 views

Grid layout component for VueJS

I'm working on a vue.js / nuxt.js project, applying the Atomic Design methodology, I need to do one to set the grid layout and using CSS Grid Layout. I already did the component, but I think I did ...
5
votes
3answers
187 views

Simple Number to Words using a Single Loop String Triplets in JavaScript

I have extensively reviewed 2 old articles on the subject: https://stackoverflow.com/questions/14766951/convert-digits-into-words-with-javascript and https://stackoverflow.com/questions/5529934/...
2
votes
1answer
51 views

Loading in two CSV files and storing them in two separate arrays

As the title says, I'm loading (or at least trying to) two CSV files and store them in two separate arrays. What I have so far worked, but it isn't the most elegant, no efficient solution. The end ...
-4
votes
1answer
380 views

The HEADING should have 2 SPAN elements [closed]

1: Create a DIV and give it a data-cart-info attribute. Inside the DIV, create a HEADING with mdc-typography--headline4" as its CSS class 2: The HEADING should have 2 SPAN elements. The First ...
5
votes
3answers
492 views

Find smallest index that is identical to the value in an array

The task is taken from LeetCode Given an array A of distinct integers sorted in ascending order, return the smallest index i that satisfies A[i] == i. Return -1 if no such i exists. ...
5
votes
1answer
43 views

Build multiple groups in an array

I have written a function buildGroupRequests() to build an array of multiple groups. It checks the size of the request group. If a request group is greater than <...
1
vote
0answers
18 views

Custom hook to handles async calls with loading and error state?

I have built this hook to handle async calls. It should manage state for the loading and ...
2
votes
2answers
40 views

Counting Valleys - HackerRank Challenge

For this challenge on HackerRank: A valley is a sequence of consecutive steps below sea level, starting with a step down from sea level and ending with a step up to sea level. Given Gary's ...
1
vote
0answers
13 views

Node Express App - Create structure around incoming payload [closed]

I am working on a simple NodeJS express app that accepts an incoming payload from a few different systems. There is a single route that ships the data off to another method and waits for the promise. ...
0
votes
1answer
33 views

Clean up nodeJS function

I'm currently writing an activity reporting system based on users; upon looking through a lot of files I'm noticing that I do a lot of if statements that clearly ...
1
vote
1answer
47 views

A solution to the Journey Planner programming challenge

Here is my Javascript solution to the following problem: Given an un-ordered list of flights taken by someone compute the person's itinerary, given a starting airport. If none valid ...
2
votes
0answers
31 views

jQuery validation for multi-page registration form

I use JS/JQuery validation for radioboxes, input field etc. Because of AJAX I use one global validation (in a separate file) and 4-5 other files to coverage actions in a relevant registration form ...
0
votes
1answer
32 views

Suppress API call in Redux Saga based on a timer

I have an API that provides data that is updated on an infrequent schedule, about once every 2½ minutes on average. Assuming that it's okay to fetch only as often as every 2½ minutes or less often, I'...
2
votes
0answers
31 views

localStorage should expire after 24 hours

The following code is checking if the user's browser is IE and if this is the case and there's no localStorage yet, it sets a localStorage, which should be valid for only 24 hours. ...
-2
votes
1answer
36 views
1
vote
1answer
21 views

Import function vs turning it into custom hook

I have this ProductSearchContainer.js file that it's getting too long to handle and maintain. What it's responsible for: Doing network requests to get a list of ...
8
votes
5answers
2k views

Find The One Element In An Array That is Different From The Others

https://www.codewars.com/kata/find-the-stray-number/train/javascript I solved this challenge by sorting from least to greatest, and checking if the first element in the array matched the second ...
4
votes
2answers
130 views

basic jQuery plugin template

I would like to know if I'm writing a plugin for jquery correctly. I followed the official guide and also added some tweaks that I've found from various sources over time. While this works perfectly, ...
1
vote
0answers
101 views

Initializing a Node JS Express Application with OOP [closed]

Overview I am attempting to learn Node JS with Express by creating a project. I have seen many examples of setting up an express.js application with functional based programming, like so: ...
1
vote
0answers
24 views

Find a Sum of Particles in A Set of Boxes Given a Number of Rows and Columns

This is a code challenge, from Codewars, the details of the specific challenge in depth can be found here: https://www.codewars.com/kata/magnet-particules-in-boxes/javascript. The summary of it ...