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
2
votes
0answers
20 views

Access object in an custom attribute efficiently

Im trying to access the attribute directly in the parent component, that why Im using the ref method. here an example of why Im trying to achieve: https://...
2
votes
1answer
64 views

Toggling a class in JS

I'm toggling the class of an element with this code but I'm pretty sure it can be written more efficiently. ...
4
votes
2answers
70 views

RegEx version control

this is my first time on this stack exchange :) I created a little script to check for the latest version of specified API version available, but I am wondering if I am using the best way possible ...
3
votes
1answer
35 views

helper function to determine if html text is wrapped with a certain tag

I have this code that I've made to parse a string of HTML and tell me if it is all enclosed within a specified tag: ...
3
votes
3answers
45 views

Simple javascript code to create an image caption

I'm trying to become better at javascript and have written a simple script that just creates some html from getting some details from some elements (e.g. the image alt text) and inserts it onto the ...
0
votes
0answers
76 views

Finding if there is sub array with sum equals to 0

I have asked to write a program to find if there is a sub-array with a sum equal to zero using JavaScript. Is this a good solution? How can I improve it? ...
4
votes
3answers
74 views

Toggling only a single class as active in a list with vanilla JS or CSS

Every time I toggle active class in a list (to dynamically change DOM content) I find that I always go to this approach to check and clear which class is active. I'...
2
votes
0answers
31 views

Node JS | From Excel to Json

Intro -> I have to convert an excel file, which comes usually in this way: to a Json file that must looks like this: ...
2
votes
1answer
46 views

Obfuscation of email and phone using JavaScript

I'm creating a new website, so I am thinking about how to protect my email address and phone number against crawlers, I actually mean email harvesters (most of which I suppose don't have JavaScript ...
6
votes
4answers
1k views

Find all letter Combinations of a Phone Number

The task is taken from LeetCode Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to letters (just ...
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'...
4
votes
1answer
56 views

Generate all possible combination of n-pair parentheses

The task is taken from LeetCode Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: ...
0
votes
0answers
38 views

Given time intervals determine if a person could attend all meetings

The task is taken from LeetCode Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] ...
2
votes
0answers
39 views

Retrieve file and other input fields from JavaScript to send to ASP.NET Core

I am currently developing an e-commerce website where users can upload their photos to customise their products. The use case begins when the user selects a product from our website (e.g. shirt). ...
0
votes
0answers
52 views

Given time intervals, find the minimum number of conference rooms required

The task is taken from LeetCode Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required....
5
votes
2answers
115 views

Improving particle performance in P5.js

I have modified a particle system to create an effect similar to the one that I want. However, with any substantial amount of particles it performs very slowly on my laptop (around 1.7 fps at the ...
2
votes
0answers
24 views

JSON flattening with object duplication on array property for CSV generation

I am looking for a way to transform JSON data into a flat "csv-like" data object. In some way, I am looking to "sqlirize" a mongodb collection. I have already check some json flat libraries in NPM ...
2
votes
1answer
95 views

Reverse Integer in JavaScript

Problem Description: Given a 32-bit signed integer, reverse digits of an integer in JavaScript. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: ...
1
vote
0answers
16 views

Simple Form Starts Long Running Task and Watches Progress

Want to level up my skills. It hits a php script that starts a long running export that can take few minutes to few hours. The export script outputs a progress file that this form's javascript uses ...
2
votes
0answers
19 views

jQuery code to display images served by PHP, without reloading

My php page displays a slider of images and when the user clicks on an image(.item), the div below (#team_single) changes the content without reloading the page. Content of the div changes also when ...
0
votes
0answers
49 views

Merge Two Sorted Lists in JavaScript

The task is taken from LeetCode Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. ...
2
votes
0answers
92 views

Javascript contact picker

I'm developing a web app that will be used privately by a company (no need for SEO and old browsers support). I made some interactive components (calendar, file manager, etc) that I am not sure if I ...
1
vote
1answer
19 views

Data models with mobx-state-tree for multiple views

Background: I'm trying to create functionality that would display two layouts of the same data. The position and size each data record must be independently saved per layout and each layout will have ...
2
votes
0answers
16 views

Querying Aurora via Node.js

Function queries data from an Aurora database. Aurora database is the MySQL engine therefore, I'm querying it with a MySQL NPM module. If there is something better, I'm all ears. The calling function ...
1
vote
0answers
39 views

Merge k Sorted Lists

The task is taken from LeetCode Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: ...
2
votes
1answer
44 views

Is this a proper way to cancel an onMouseOver which uses setTimeout? (Vanilla JS)

I've got a working solution for an onMouseOver event which rolls over a set of images and replaces them in the element. Due to my lack of knowledge in JS I would ...
3
votes
2answers
38 views

Javascript Object of Arrays manipulation

I am writing a function to decode data from a run length encoded format like: ...
0
votes
1answer
35 views

More elegant solution to create a array of fake data

I am creating fake data using faker.js. Out of simplicity I created a for-loop. ...
11
votes
5answers
2k views

Check if three arrays contains the same element

Do 3 arrays contain a common element, if they contain output it. For example: [1,2,3], [2,3], [2,4] -> answer = 2 ...
4
votes
0answers
32 views

Vuejs - input validation

I'm in a project that's currently using vue. I'm at the moment developing validations for the inputs and in a way to make them more flexible, my idea was to create an intermediate component "Group ...
3
votes
1answer
52 views

Whitelist for textarea and save input to file

I'm working with product codes, so a user can only scan these type of product codes into a textarea. I don't know if my code is written the best way possible, or has good performance. I'm using a ...
4
votes
0answers
87 views

Merge Intervals in JavaScript

This task is taken from Leetcode - Given a collection of intervals, merge all overlapping intervals. Example 1: ...
1
vote
0answers
42 views

Combine multiple if statements with multiple properties [closed]

I'm looking into using my loop to combine and narrow down this piece of code into maybe a switch statement or other methods, how would I be able to achieve that? This is what I have so far which has ...
2
votes
2answers
41 views

Phrase scrambler

To practice my JavaScript skills, I wrote a phrase scrambler. I would appreciate feedback on code efficiency and readability, as I want to know the best practices for further development. ...
2
votes
0answers
15 views

KaTeX extension to Markdown

I've created a JS snippet to enhance markdown at display-time with KaTeX math rendering. (Specifically, this is mostly for documentation of math-heavy libraries where the host language documentation ...
3
votes
0answers
51 views

Node.js tool to update Cisco UCCX with CSV data

What this tool does update skills for agents on a Contact Center Cluster (Cisco UCCX). The tool reads a csv file called agents.csv from the current working directory. This file has a list of agents ...
3
votes
2answers
44 views

jQuery dynamic toggle class function

I wrote this function that will toggle a class of a targeted element. Applying the class js_class_toggle to any element will trigger the function when clicking on ...
3
votes
2answers
56 views

Check if object contains only empty nested objects

lodash.isEmpty([{}]) returns false even though the object contained in the array is empty. I need something that considers ...
23
votes
7answers
6k views

Trapping Rain Water

This task is taken from Leetcode - Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. ...
2
votes
1answer
46 views

React component to animate planets on a canvas

I wrote some JavaScript to generate some graphics on a canvas, on a regular HTML page. I now want the same code to run in a component that is part of a React app. I've done this: ...
2
votes
3answers
63 views

Jewels and Stones

The task is taken from leetcode You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you ...
4
votes
2answers
96 views

JavaScript implementation of insertion sort

I just started reading Introduction to Algorithms and the first algorithm introduced is the insertion sort. Even though the sort seems to work, I thought I'd ask for feedback right at the start since ...
3
votes
1answer
77 views

Non brute force algorithm for Birthday Chocolate

Problem: https://www.hackerrank.com/challenges/the-birthday-bar/problem Lily has a chocolate bar that she wants to share it with Ron for his birthday. Each of the squares has an integer on it. She ...
15
votes
2answers
499 views

Convert camelCase and PascalCase to Title Case

I'm trying to take camelCase and PascalCase strings into a function and spit them out as Title Case. This function also needs to be able to handle odd PascalCase strings with capitalized abbreviations ...
3
votes
0answers
33 views

Find the starting indices of all occurrences of the pattern in the string - KMP algorithm follow-up

The task was initially solved here, but was too buggy: Given a string and a pattern, find the starting indices of all occurrences of the pattern in the string. For example, given the string "...
2
votes
1answer
43 views

Number of Islands

The task is taken from leetcode Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands ...
1
vote
0answers
24 views

Javascript Calculator which implement Stack

I have re-write a new version of Javascript Simple Calculator. Any thoughts in regards to this new design and how can it be improved further? One of my thoughts are to create a Javascript object for "...
1
vote
3answers
75 views

Find the starting indices of all occurrences of the pattern in the string [closed]

The task Given a string and a pattern, find the starting indices of all occurrences of the pattern in the string. For example, given the string "abracadabra" and the pattern "abr", you should ...
1
vote
0answers
21 views

Extract useMemo to its own custom hook

I wanted to know if the useMemo function extracted like this is valid at all. This is a whole component (Sorry for the imports) that uses useMemo to get a data that is grabbed from the server using ...
1
vote
0answers
34 views

Tic Tac Toe finish the game function [closed]

currently i am working on javascript. Learning deep etc. So i decided to made my own tic tac toe game 4x4 without any tips. Then i stucked. If anyone can help me will be perfect. Game is playable ...