Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
1answer
44 views

Fetch text values from JSON and Display pop onclick text

I have below code which will fetch the text from json & onclick text , display pop up box in page.... Now i need to give options to change font-family, font color.... But Adding the code in the ...
1
vote
0answers
30 views

Hackerrank Beautiful Strings

Problem Statement You are given a string, S , consisting of lowercase English letters. A string is beautiful with respect S to if it can be derived from S by removing exactly 2 characters. ...
-3
votes
2answers
47 views

Simplify else if statements in JS for a prompt to code? [closed]

How do I simplify else if statements? I want the code to be able to run a bunch of code based on the users input, such as bring to link for some of them, so I am not looking for ...
1
vote
0answers
32 views

Rethrowing Error through several classes

This is a simplified version of my app. It has a bunch of scraper classes, and a Job class, which controls the collection of data, and the saving to the db. During scraping it could happen many ...
2
votes
0answers
61 views

Return whether a string is a palindrome if you can delete at most k elements

The task: Given a string which we can delete at most k, return whether you can make a palindrome. For example, given 'waterrfetawx' and a k of 2, you could delete f and x to get '...
1
vote
0answers
53 views

Rotate a list by k elements

The task: Write a function that rotates a list by k elements. For example, [1, 2, 3, 4, 5, 6] rotated by two becomes [3, 4, 5, 6, 1, 2]. Try solving this without creating a copy of the list. ...
4
votes
2answers
252 views

Possibly bubble sort algorithm

I'm trying to figure out what to call this sorting algorithm: ...
9
votes
2answers
425 views

A function which translates a sentence to title-case

The task is to write a JavaScript-function which translates a given blank-separated sentence to title-case. Means that all words shall start with a capital and then the rest of the word in lower-case....
0
votes
1answer
28 views

Making two sequential asynchronous requests using promises

The following code is making two asynchronous requests to obtain the desired data. The second request needs to access the data from the first request, hence I need to nest it. I know that it is better ...
1
vote
1answer
34 views

Loop through data layer and display dynamic content [closed]

The purpose of the pricingTest object is to grab pricing information from the dataLayer on the page and render content blocks accordingly. My goal in posting this is to hopefully receive some feedback ...
2
votes
1answer
65 views

Executing multiple steps to handle a purchase using currying

Is doing something like this utilizing currying in a practical sense? ...
1
vote
0answers
65 views

Sort a list using a reverse helper function

The task: Given a list, sort it using this method: reverse(lst, i, j), which reverses lst from ...
1
vote
0answers
28 views

Nesting 3 divs within another div using JavaScript [closed]

For a class that I'm in, we're creating digital Pokemon cards. I'm trying to create elements that are nested within another element and repeated multiple times. For example, I have currently: ...
1
vote
2answers
55 views

Find the smallest distance between any two given words in a string

The task: Find an efficient algorithm to find the smallest distance (measured in number of words) between any two given words in a string. For example, given words "hello", and "world" and a ...
1
vote
1answer
103 views

User upload & Drag image and update text

I am allowing user to upload images & drag uploaded image once user click on mask images, also gave an option to Edit the text.... I am fetching mask images and text from json file.... I am ...
0
votes
1answer
54 views

Formatting milliseconds as days, hours, minutes, and seconds [closed]

This is a function which aims to convert an amount of milliseconds to a more human-interpretable Day(s) Hour(s) Minute(s) Second(s) format: ...
1
vote
2answers
54 views

Good Vs. Evil - Battle For Middle Earth - CodeWars [closed]

This is the code that I'm submitting for the "Good vs Evil" Kata on CodeWars: https://www.codewars.com/kata/good-vs-evil/train/javascript ...
1
vote
3answers
43 views

Javascript array_count_values function [closed]

I am using an array_count_values function since I have translated the code from php to javascript and javascript does not have this function, but not sure on the ...
5
votes
1answer
98 views

Return the first recurring character in a string

The task: Given a string, return the first recurring character in it, or null if there is no recurring character. For example, given the string "acbbac", return "b". Given the string "...
2
votes
1answer
38 views

Google Apps Script to create an invoice

I am using Google Execution API to create an invoice and it's a small part of a bigger system. However, my boss is pretty displeased at the total execution time before an invoice is generated. It ...
4
votes
1answer
73 views

Determine whether any permutation of a string is a palindrome

The task: Given a string, determine whether any permutation of it is a palindrome. For example, "carrace" should return true, since it can be rearranged ...
3
votes
1answer
80 views

AWS Lambda function to update newly added DynamoDB records

Approach All data is submitted into my DynamoDB from another Lambda > API Integration function whereas the lastUpdated row gets inserted as ...
1
vote
0answers
11 views

UI Event Flow class

Here is a JSFiddle. Class Definition: UIEvent ...
2
votes
2answers
27 views

Brainfuck interpreter improvement

I created a brainfuck interpreter in javascript. It works good to me as I have seen no bugs in my compiler. I like to get a suggestion and review from you to what should this compiler improve. Here'...
0
votes
1answer
80 views

Updating values in a database

I'm using standard jQuery Ajax to update values in the database and reflect the result in an output. This repetition seems like bad practice and I don't know enough about jQuery to consolidate this ...
2
votes
2answers
27 views

Ramda - Forming a string based on array of word positions

I saw this question and wondered how it'd be best to accomplish this using Ramda. I'm new to the library so I thought it'd be an interesting learning exercise. I have a working solution but it seems ...
3
votes
1answer
46 views

Replacing GitHub usernames with links

A user wrote an issue asking if inside the bio (or any arbitrary tag), any tagged accounts can be automatically linked like on Github. I gave them this function: ...
10
votes
3answers
1k views

Find the majority element, which appears more than half the time

The task: Given a list of elements, find the majority element, which appears more than half the time (> floor(len(lst) / 2.0)). You can assume that such element exists. For example, ...
1
vote
0answers
34 views

Using promises to zoom to a project, then to a task or comment

How to beautify this part of code? (I mean usage of promise in promise) I really have no clue how this could've look like. ...
2
votes
0answers
45 views

React code to build shopping cart

I have built a basic shopping cart simulator. All it does is add and remove items between two different basket (i.e. aisle vs basket). While working on the problem I started to think about the ...
3
votes
1answer
37 views

Monte Carlo pi animation

I have created a program that calculates pi using a Monte Carlo method. It also animates the process and displays the value as it is updated to show how it gets closer and closer to the actual value ...
3
votes
1answer
64 views

PHP AJAX handler to fill an HTML table

I would like to know if this code follows recommended practices and standards for AJAX/PHP calls. Can this AJAX + PHP code be improved in terms of security, performance, etc.? ajax.js: ...
2
votes
1answer
35 views

Get _m_s time format from milliseconds value

I could have any value in milliseconds like: 1040370 I must alert a specific converted time format : _m_s (ie:17m20s) Here ...
11
votes
5answers
792 views

Easy to read palindrome checker

I made a palindrome checker that's supposed to be designed to be simple and easy to read. Please let me know what you think. I believe the time complexity is \$\mathcal{O}(n)\$ but I'm not too sure ...
1
vote
0answers
47 views

Find the square root of n

The task: Given a real number n, find the square root of n. For example, given n = 9, return 3. My solution: ...
1
vote
0answers
14 views

Creating Google Charts on SharePoint

I was creating a script to pull data from a SharePoint list and display its contents in graphical form on another page. My original script was very messy and I had asked advice on how I should ...
-2
votes
2answers
44 views

Optimizing JS code

I have two variables that could be the same. In such a case I am assigning one of them to be undefined. Is this code the best way I can write it? ...
3
votes
2answers
97 views

Find the elements that appear only once

The task: Given an array of integers in which two elements appear exactly once and all other elements appear exactly twice, find the two elements that appear only once. For example, given ...
3
votes
1answer
51 views

Flappy Bird game supporting local multiplayer of up to 2 players

The game is hosted here. GitHub repo This is my first Phaser 3 game/project and I'm still pretty new to Javascript so I'm sure there are many things I could be doing better. The number 1 thing that ...
0
votes
1answer
38 views

Extracting grouped objects into a flattened list

I need to optimize this javascript method because it is a bit slow, I don't want to use the flat() command, as for some reason my angular6 app does not understand the vanilla flat() command, or ...
1
vote
1answer
49 views

Mandelbrot Set generator

I want to reduce the big time it needed for my mandelbrot set generator to work. I'm working this for already a week. I tried to reduce the canvas size from 400 by 400 to 200 by 200 and the speed ...
1
vote
1answer
35 views

Remove excessive recurrent code from store and computed

I have three getters in my store: ...
0
votes
1answer
31 views

Handling a PUT API call to write to a database using promises

The following function is accepting PUT connection to a server API, checks authorization to write and then performs write to a database. The eslint linting tool ...
2
votes
1answer
22 views

Recamán Sequence Animation

I wrote a program that animates the Recamán sequence. It is in uses HTML canvas and JavaScript. I was hoping for some feedback on how it could be improved. ...
1
vote
0answers
19 views

Extract and manipulate date from SharePoint and export into Google Charts

I am extracting a list of data from a SharePoint library with CSOM, then manipulating the data to give some sort of visible statistic through Google Charts. The data is a list of each parent ...
1
vote
1answer
45 views

Find nearest k points from the central point

The task: Given a list of points, a central point, and an integer k, find the nearest k points from the central point. For example, given the list of points [(0, 0), (5, 4), (3, 1)], the ...
1
vote
1answer
61 views

Edit and delete uploaded images code inside script tag

I am Displaying mask images & allowing user to upload the custome image inside mask image, now i want to give an option for user to Edit & Delete the Uploaded image.... Video link : https://...
2
votes
2answers
44 views

jQuery redirect form

I'm using jQuery to create a (hidden) form that redirects people to another page using JavaScript. ...
2
votes
1answer
32 views

Form validation in a variety of different ways depending on the field input

I've created code in JavaScript for a form validation in a variety of different ways, including if the field is empty, if it contains special characters, if it has numbers/letters when it shouldn't ...
0
votes
1answer
31 views

JS to create Table data dynamically

The following codes generate table row dynamically. I wonder if there are better ways of generating the same data. Also instead of manually coding the heading and the table itself, is it possible to ...