2022 Developer Survey is open! Take survey.

Questions tagged [javascript]

JavaScript is primarily a language focused on web development. Being a monopoly on the front end and having Node on the back end. Use this tag for questions regarding vanilla JavaScript; optionally tagged with an ECMAScript version. If you are using a preprocessor such as TypeScript please tag with that too.

Filter by
Sorted by
Tagged with
0 votes
0 answers
42 views

Can I optimize my implementation of generating Fibonacci series using recursion?

My function accepts a number, which generates total Fibonacci numbers. I am using recursion. Please follow the code below, ...
user avatar
1 vote
0 answers
27 views

Process a binary file by chunk using a read stream in nodejs

I want to process a file chunk by chunk to prevent memory exhaustion. I need to consume the file using a read stream. When trying it, this implementation seems to work fine. I am asking your expert ...
user avatar
-2 votes
0 answers
13 views

How do I make this jQuery not wait for document [closed]

I'm trying to not make the document wait until it's completely finished loading, I just want the code to run normally, how can I modify this code so that the document isn't waiting? ...
user avatar
0 votes
0 answers
19 views

Async recursion that must ultimately return a promise [closed]

I have an asynchronous function that must ultimately return a Promise (the first function). This function has many tasks but I've stripped them all down to just one for clarity. One such task is a ...
user avatar
  • 113
0 votes
1 answer
22 views

Spawning a child process that is accessible in global scope through use of eval()

So basically my question is what would be a better way to achieve my goal? The code below works fine but looks like it is extremely inefficient and could be achieved in a better way. The code ...
user avatar
  • 103
1 vote
1 answer
48 views

A reduce method which aggregates common data in objects

I built a method using reduce of JS to aggregate together data from a DB in a better shape. What I'm wondering is, if that method can be simplified with a more ...
user avatar
  • 229
-1 votes
0 answers
37 views

Game based loosely on cricket

Cricket is a PC game which is similar to real cricket but has little different rules There will be N number of players , Y number of overs, here one over means each player will hit one ball each, let'...
user avatar
0 votes
1 answer
22 views

Show/hide depending on ID and Class

I have written some code that shows a div class, based on what ID is clicked. I'm a beginner, so not sure how to make this code compact, it seems way too long at the moment. Can anyone suggest a ...
user avatar
-2 votes
0 answers
24 views

Removing \n and \f from a string [closed]

I am trying to remove \n and \f (I'm not sure what they are called, I know \n is a new line) ...
user avatar
  • 1
1 vote
3 answers
72 views

Printing the first n numbers of the Fibonacci sequence

I have written a code below for printing the first n fibonacci numbers, the code is as follows ...
user avatar
1 vote
1 answer
19 views

Sidenav menu that appears when click on button

I have a side menu that appears when click on button, which works fine. But now I want to clean up my code, shorten it if possible. I was wondering if there is an easier and cleaner way to achieve the ...
user avatar
  • 11
1 vote
2 answers
38 views

Beginner bank app withdrawal transaction

Pooja would like to withdraw X USD from an ATM. The cash machine will only accept the transaction if X is a multiple of ...
user avatar
0 votes
1 answer
27 views

Navigating a javascript object (previous and next)

I am using Vue3 together with Collect.js. I have an object records that can have n number of items. On my website, I display ...
user avatar
  • 237
1 vote
1 answer
40 views

Slug Generator in Javascript

I've built a small slug generator that will take an input from a user and replace all of the spaces with dashes to create a nice looking slug. I'd appreciate any tips to make my code better. ...
user avatar
0 votes
0 answers
14 views

Find index of element within a list of elements with the same class

I have asked this question on stack overflow however I didn't receive an answer which solved the issue so I created one myself however I am wondering if there is a better/ simpler way to do it. Say I ...
user avatar
  • 163
0 votes
1 answer
31 views

Rock, paper, and scissors game

I followed a tutorial that goes through different practical examples and challenges using vanilla Javascript, HTML and CSS. I just completed a simple rock, paper, scissors game; however the tutorial ...
user avatar
0 votes
3 answers
61 views

Sum up nested array of objects based on keys

I have this function that should take some array of objects and sum up the values of the inner objects based on some keys, and conditionally add to it some values from another object. Is there a way ...
user avatar
  • 189
1 vote
1 answer
43 views

Calculate the value of PI in JS

I have created an algorithm which calculates the value of PI in JavaScript. Can this algorithm to be improved? ...
user avatar
  • 153
1 vote
1 answer
29 views

Chaining backend calls from VueJS method using Axios

This is the first ever bit of front-end code I have ever written, I have tried to adapt the existing call that is there to the backend using axios, so I check on of the response object value using the ...
user avatar
  • 487
1 vote
1 answer
67 views

Add and delete books into this bookshelf vanilla javascript project

In this project I was supposed to add and delete books by author and title by pressing the submit and delete button. There is a video that illustrates how my project works. I did it using two ...
user avatar
0 votes
3 answers
77 views

Destructuring an object in JS

The solution I have written is working as expected, but here is my function: ...
user avatar
  • 1
1 vote
1 answer
41 views

Typescript simple observable state and web component

I've been experimenting with wiring up a vanilla web component in a reactive manner to a state box. The goal is that when something changes on the state object, the web component reacts. I realize ...
user avatar
  • 113
0 votes
1 answer
28 views

range slider show/hides and reset (vanilla js)

I have a HTML5 range slider. i.e. ...
user avatar
-1 votes
1 answer
63 views

Script becomes too big

I'm trying to increase the number of elements in the #source div from two to three and so on. But in order to increase it each time, I will need to create a lot of new lines of code with pretty much ...
user avatar
  • 7
0 votes
1 answer
28 views

Asynchronous recursive function for generating a unique Id

The code below is my first purpose built asynchronous recursive function. It took me a while to figure out how to write the thing, and I would like a second opinion. It's part of a project for The ...
user avatar
1 vote
4 answers
103 views

Find first and last matches on a sorted list

I needed a function to find the first and last indices into a sorted list corresponding to a given value (roughly similar to C++'s equal_range()). This is the ...
user avatar
0 votes
1 answer
32 views

Replace the src of an image for each link in a nav menu

I have this giant wall of code, which replaces the src of an img on the page with the one specified, for each link in a nav menu. But... it's a giant wall of code, calling up the action for each ...
user avatar
0 votes
0 answers
13 views

Effective cache solution to have the newest data in React Native

Goal We have an app with different articles. I want to cache an article when the user has read it, but make sure that I display the latest data. I came up with this hook: ...
user avatar
  • 101
1 vote
1 answer
82 views

Three efficient JavaScript functions that converge to pi extremely fast

I am learning JavaScript and decided to translate my Python scripts into JavaScript. Approximations of π are extremely popular programming challenges and I am sure they must be a staple of the ...
user avatar
1 vote
0 answers
51 views

Cookie Clicker on JS, with Buttons for upgrades

I'm new to JS, so I'm most likely coding badly. Can you please point out the errors and correct the code? the site complains that it needs to write more text, but I don’t know what else to write HTML ...
user avatar
1 vote
1 answer
87 views

JavaScript function that generates Fibonacci like sequences of given order

Generalizations of Fibonacci numbers Fibonacci numbers of higher order A Fibonacci sequence of order \$n\$ is an integer sequence in which each sequence element is the sum of the previous \$n\$ ...
user avatar
1 vote
1 answer
53 views

A simple JavaScript function that does prime factorization

This is a simple JavaScript function that does prime factorization. I wrote it on an Android phone with online editor (I don't have access to computers in night time): Code: ...
user avatar
2 votes
2 answers
119 views

FizzBuzz in JavaScript (node.js), my first JavaScript program

I had just decided to learn JavaScript, so I wrote this program. I am sure you know what FizzBuzz is so I wouldn't describe it here. Console output: ...
user avatar
1 vote
2 answers
151 views

Tic-Tac-Toe vanilla JS Pseudo OOP

I'm working on building a simple game in vanilla JS (tic-tac-toe). Some weeks ago I created a functional MVP and asked some questions about it (Vanilla JS Tic-Tac-Toe). The code worked, but it was a ...
user avatar
  • 119
0 votes
0 answers
31 views

Compare aggregate values of data grouped by date

I've got a working code that transforms data from a MySQL database. Currently, it's inefficient because it uses about loops, which you'll see at the bottom. I get an array of objects from a database ...
user avatar
  • 101
0 votes
1 answer
30 views

Is my approach for Palindrome right or is there a better way to do it?

The code below is for checking whether the input string is palindrome or not ...
user avatar
1 vote
0 answers
15 views

Iterating over de Bruijn sequences in JavaScript

I have just put this code together, it's not quite the most elegant but it seems to get the job done. Does it seem alright? I could not find anywhere a "de Bruijn sequence algorithm", so I ...
user avatar
  • 299
-1 votes
1 answer
35 views

Javascript grabbing sum

I'm wondering how the following looks for a javascript Array-sum function: ...
user avatar
  • 333
-2 votes
1 answer
36 views

Update button onclick using Jquery [closed]

I'm updating this onclick function and wanted to ask if this the best way to do this? ...
user avatar
  • 109
1 vote
1 answer
26 views

How to optimize clz count leading zeroes manual implementation?

I have gathered from around the web a few functions and such to land on this: ...
user avatar
  • 299
3 votes
1 answer
68 views

User registration and login service using JWT

I have created service to communicate with my backend for user registration and login. I use the JS fetch API and send all data through HTTPS. I use JWT tokens to authenticate queries once I have ...
user avatar
  • 133
1 vote
1 answer
70 views

Categorise amount into "small", "medium" and "large"

I have a super simple function that returns a text label for a range of the input ...
user avatar
  • 275
0 votes
0 answers
22 views

How to optimize Uint8Array#replace in JavaScript?

I am considering implementing a string type in JavaScript, in a programming language that compiles to JS/Swift/Kotlin/Rust. So I have here implemented a prototype of how the ...
user avatar
  • 299
0 votes
0 answers
46 views

Clicking image makes select option changed, and vice-versa in jQuery

I'm using jQuery version 3.6, and I have image labels that are clickable and when the user clicks on it a select option is being selected. And vice-versa, when a user selects an option an image is ...
user avatar
0 votes
0 answers
24 views

React Native clean up firebase function

I've been working on my personal project, using React Native and Firebase. Recently, I've encountered the following error on multiple occasions: ...
user avatar
  • 53
2 votes
0 answers
103 views

Simple websocket chat app

I'm coding a simple websocket chat app. I was wondering if my code is secure and efficient. I also have a question about the way how I'm sending objects and then checking the type, is there anything ...
user avatar
  • 21
1 vote
1 answer
42 views

Convert filter button from plain Javascript to Jquery

I have the following function written in JS: ...
user avatar
2 votes
1 answer
33 views

Javascript function which polls an async endpoint and inserts the result in a web page

I read about debounce this morning and ended up needing something similar to the concept in real life this evening to build a poll that checks whether a link I receive from an async call is ready to ...
user avatar
  • 21
1 vote
0 answers
28 views

A Command Line To-Do List (CLI) application written in NodeJS

I wrote this code for myself so I can manage my personal to-do list easier. Considering, I spend most of my time in the terminal, it made sense. I have worked on the project as a way of practising my ...
user avatar
  • 11
0 votes
0 answers
24 views

Two different JavaScript implementations of the observer pattern using class inheritance and concatenative inheritance

To practice design patterns and JavaScript, I'm implementing the observer pattern in two different ways: One implementation using class inheritance And another implementation using concatenative ...
user avatar
  • 729

1
2 3 4 5
193