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
-1
votes
1answer
66 views

Check if a website is in a certain language and if so, block it

I try to block all websites in Hebrew because I want to give more time on websites in other languages. Given that many webmasters don't add ...
-1
votes
0answers
26 views

Does this JavaScript code violate production code logging principles? [closed]

Here's a stub version of a piece of JavaScript code: ...
-5
votes
0answers
10 views

How can I redirect iframe javascript code to an external site? [closed]

I am struggling with the code below. It was given to me by another researcher, and while I have a lot of coding experience. I have very little web development experience. The code below runs an ...
2
votes
2answers
58 views

Leetcode First Unique Character in a String code optimisation

I was working on First Unique Character in a String Question Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. Example 1: ...
2
votes
1answer
34 views

iterating a big list of objects throws a memory issue

I'm writing a function which iterate through a list of objects and should return: true if all the items have the attributes (cp and type). false if all the items haven't the attributes (cp and type). ...
0
votes
1answer
53 views

Get data from a chain of lists

I have 3 different lists which I get in 3 separate API calls. persons 2. cars 3. categories ...
1
vote
0answers
58 views

Express.js and jsonplaceholder application

I have put together a small node application with Express.js and jsonplaceholder. On the homepage, it displays posts by all users. You can also filter posts by one user (author). In ...
3
votes
2answers
148 views

Check for max value in stack

Got this problem in a coding interview - Get the max value of a stack in O(1). The stack contains numbers only. Please review my solution. ...
1
vote
0answers
33 views

Higher-order function to do throttling, written two ways

I have used below method for throttling which is a Higher Order Function (HOF), but find some difficulties to choose which one is better way to write it. Below are both methods. return of the ...
0
votes
0answers
32 views

Multiple flatMap style: Nested or sequential?

This question applies to any language with flatMap -- e.g. functional languages -- but I'll use an example in JavaScript. I'm working my way through Functional Programming in JavaScript, which is a ...
0
votes
0answers
35 views

Creation of a header file

So I've created this Header to include in all my PHP files, and think everything works as it should for now. But since it's the first time I'm creating one, I wanted to have it reviewed just to learn ...
2
votes
1answer
35 views

word frequency distribution

wordList is an array of non-empty strings ("words"). The following code I have written with the purpose of obtaining a Map, containing the unique words ...
-1
votes
1answer
65 views

Order array based on rating in a specific order

I have to sort the an array based on rating in a specific pattern. 3 star = 5, 4star = 3 , 5 star =7 [3 star hotel, 4 star hotel, 5 star hotel] Note: Replace 3 star hotel with 4 star hotel if 4 star ...
0
votes
0answers
19 views

Order array based on rating in a specific pattern [duplicate]

I have to sort the array based on rating in a specific pattern. 3 star = 5, 4star = 3 , 5 star =7 [3 star hotel, 4 star hotel, 5 star hotel] Note: Replace 3 star hotel with 4 star hotel if 4 star ...
0
votes
1answer
58 views

Find when the shop will next open or close

Intro: I started working three month ago and i have never used JavaScript before, i don't know what is the best practice in JS and i feel like my code can be improved a lot, so i'm here searching for ...
0
votes
2answers
44 views

Test strings with a lot of regular expressions

I've a list of strings and a list of regular expressions. I need to categorize each string to get what type of string it is based on regex. This is my code: ...
0
votes
0answers
33 views

Iterative solution for Tower of Hanoi challenge

Recently I'm interested in the Tower of Hanoi problem. The simplest solution is probably the recursive one but I'm trying to challenge myself by solving it iteratively. After observing the pattern of ...
0
votes
1answer
46 views

custom array sorting algorithm

So I came up with a "new" sorting algorithm: ...
2
votes
2answers
48 views

Find the 'n' most frequent words in a text, aka word frequency

I'm doing freeCodeCamp's Coding Interview Prep to improve my JavaScript skills. This challenge is called "Word Frequency", and is based on the Rosetta Code's entry of the same name. The ...
0
votes
3answers
176 views

C# 'out' keyword in JavaScript [closed]

Since I met the out keyword in C#, I'm trying to find an equivalent in JS. So, please take a look at the code and leave your opinions or suggestions about this. C# ...
2
votes
2answers
34 views

Calculate cumulative daily rainfall

It took me a while to compute this script, it works perfectly, but I think that it is very raw and long. The goal of the script is to produce a graph of cumulated rainfall with 3 lines: Cumulated ...
4
votes
2answers
72 views

find closest distance between two numbers (looking for improvement)

Let's say I have a number set like below // 1,2,3,4,5,6,7,8 Now I want to go from 2 to 5. ...
0
votes
1answer
34 views

Regarding "Local variables should not be declared and then immediately returned or thrown" [closed]

Given the code: async getData() { const response = await handleRequest(…); return response; } Many of static code analyzers mark this code with an issue ...
0
votes
0answers
37 views

Beginner Q: Is there a cleaner way to group a list in JS?

I'm looking to highlight some words on a webpage, I've grouped them now, but changed the css and html slightly and this seems to have broken it. For context, looking to add a list of words in JS which ...
0
votes
0answers
10 views

Passing global state and state-modifying functions to child elements in a React app

I'm only three days into React, so please forgive my ignorance. I'm working on an application in which you can design something consisting of various parts. The interface has a list of items in one ...
1
vote
1answer
14 views

A more elegant way of adding option data to a dropdown box using jQuery

The code I have below is currently what I am wanting to see if I can shorten. The code works as-is right now but I don't like the face that each IF statement has its own $each loop in it. ...
0
votes
1answer
47 views

React - Display current time using useState, useEffect

I am learning about hooks, so I try to write code that display current time. I had comment in each line of code the reason I write it. So: Am I understand right? Is there any bad practice? What need ...
3
votes
1answer
41 views

Simple button webcomponent

I'm starting out on a project that will standardise some increasingly complex webcomponents. In a final version the goal is to support multiple different design systems (as the components might be ...
0
votes
0answers
11 views

validating start and end year with return statement

I have done some validation in the following code and wanted to know if that's the correct way to go about it. The validation is related to start year and ...
2
votes
1answer
27 views

Arithmetic quiz on the command line

I am writing a program that asks questions, takes the user's input, and responds according to whether the answer they gave is correct or not. I am looking to improve my code with respect to ...
0
votes
0answers
32 views

Crud operations for profiles with React hooks

I'm creating a small app to get familiarize with React. I'm trying to follow the pattern introduced in this Kent C Dodds article. But I have more states than the article. Here is my initial state <...
2
votes
0answers
25 views

Vanilla Javascript Calculator using ESLint Air BnB Style

https://kdevcalculator.web.app/ Code: https://github.com/AmishBaztard/Calculator/blob/main/script.js Just looking for a code review on this. I used ESLint Air BnB Style. ...
0
votes
1answer
25 views

get distinct objects from an array based on a subset of keys

I've written some code that is yielding the desired results but it seems verbose. The code gets the distinct objects from an array of objects when looking at only a subset of the keys. Is there a ...
0
votes
1answer
86 views

Building user friendly inputs on a mobile device

I am working on an e-commerce website. The home page has 2 inputs: Looking for and Location. The user would enter their desired product and location and click on Search as shown below: The first ...
1
vote
0answers
20 views

Changing game mode in Tic Tac Toe [The Odin Project] [closed]

I'm posting this here mostly as I posted it over at stackoverflow because the user that answered me recommended it: I'm learning to code with The Odin Project. So far, I've been doing every project ...
0
votes
0answers
26 views

Vue and JSONPlaceholder application

I have put together this small application that uses the JSONPlaceholder API and Vue.js. The application crosses users and posts and displays the posts by user (author): ...
8
votes
3answers
787 views

Check if calendar week number falls within two other week numbers

I want to check with Javascript if a week number (with year) is within two other week numbers. Example data: Year-Week ...
2
votes
1answer
42 views

Check RSS feed and post to Discord

I'm new to using JS for anything other than DOM manipulation, so I'm not sure if the following code is taking full advantage of the Async concept in JS. This is an example of a function I'm writing in ...
2
votes
1answer
46 views
-1
votes
0answers
46 views

Can this html generating function be simplified?

I have a function generate_html that produces an html string. The method is several lines long. I believe that it could simplified, but I'd like to get some advice. ...
0
votes
3answers
70 views

Convert a fraction into a whole number and a binary exponent (eg 3.125 => 25, 3)

I have a function which takes one argument, a fraction, and returns two numbers - an integer and a power of two. So, when you divide the the integer by 2 raised to power power of two, you get the ...
3
votes
0answers
28 views

Calculate difference between dates and output desired result like (Today, Tomorrow, or 20 Days from now)

I'm writing a task list tracker with VueJS. Each task has a Frequency label (How often it needs to be done), Last completed date label (When the task was completed ...
4
votes
2answers
876 views

Is there a simpler way to sum the lengths of arrays within an array of arrays in JavaScript?

I primarily work with C#, and when working with an array of arrays, I can sum the length of the sub arrays using Linq: ...
0
votes
2answers
37 views

Add Properties from one array of Objects to another array of Objects based on property id

I do have my code running but again I'm wondering if there is a nicer solution since mine seems to be clumsy and I'm wondering if there is a better way like chaining (but I can't work out how to do ...
1
vote
0answers
37 views

Chess quiz web site

I'm working on a personal project to build a website that quizzes users on chess opening theory moves. I know my code is not very object-oriented but I am working on refactoring it right now. I just ...
0
votes
1answer
51 views

Is it possible to get a better performance using memoization? Array algorithm

I have a working solution for the problem below. I have the feeling that it could be improved using memoization, but I cannot see how to do it. The problem: You are given an array arr of N integers. ...
2
votes
0answers
15 views

Word Matching Exercise Game

I have a simple program that matches words with descriptions. The program should do the following. Allow a user to enter a set of inputs: keys and descriptions. When the user clicks generate html a ...
0
votes
0answers
21 views

Overly complex code for a seemingly simple idea. Fulfilled promises returned instead of values

I have a React hook "useFetchSales" that fetches all documents from the "sales" collection in Firestore: ...
0
votes
1answer
101 views

How to deal with nested callbacks in a clean way?

I am currently migrating some code from class-based components to function components using hooks in React. Where I have come across a piece of code that works as expected but there are 3 Axios calls ...

1
2 3 4 5
189