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

Checking if variable is defined before accessing its properties [closed]

I didn't write this but I noticed it in our codebase at work. ...
3
votes
3answers
135 views

fizzbu| - Fizzbuzz with dynamic height

Here is a variation on a theme: fizzbuzz. After providing this answer recently, I decided to practice some VueJS skills with outputting the values and conditionally applying styles based on the value. ...
3
votes
1answer
354 views

Tip Calculator in pure JS

A simple tip calculator that asks for the total bill amount, service quality (used to determine what percentage of the total cost will be tipped), and how many people are sharing the bill (used to ...
3
votes
2answers
2k views

Simplifying Counter of Checked Checkboxes

Is the following code a proper solution to my problem? I have a feeling it can be simplified quite a bit. If one of the first four checkboxes is checked the sum is 1; if two 1.5; if three 2; if ...
3
votes
1answer
283 views

Tic tac toe game in a web browser

I have this tic tac toe game which is very old project of mine, though I made some changes on this to improve the script to perform better. This game is functional, Any logic improvements or other ...
3
votes
1answer
77 views

Can phrase be made from whole words in another string?

I am working to solve this HackerRank puzzle: Hash Tables: Ransom Note The premise is that if I am given a string like this: give one grand today I can find a match for each of the words in the ...
3
votes
0answers
54 views

Fast algorithms in Javascript for shortest path queries in directed unweighted graphs

(There is a follow-up question available to this: Follow-Up Question) So I have this: ...
3
votes
4answers
2k views

JavaScript Random Color Generator

I made a page to generate a random color with JavaScript and set that color to the background of the page. ...
3
votes
1answer
423 views

Wrote javascript version of error monad / monadplus, did I obey monad laws correctly?

Just looking for some critiques hopefully from haskellers of how I might be breaking monad laws or just monadding all wrong. My or is something like the ...
3
votes
1answer
412 views

Canvas spatial grid collision

You can see a working example here. Be sure to click on the canvas or the key inputs will not be detected! Are there any ways I could improve upon this? Anything that should have been done ...
3
votes
2answers
290 views

Alternative implementation of isType()

Detecting types in JavaScript sucks This answer discusses the standard way to check the type of a JavaScript object (specifically, an array): The method given in the ECMAScript standard to find ...
3
votes
1answer
274 views

Simple object-oriented calculator - part 4

This question is an improvement I did based on recommendations from these other questions: Simple object-oriented calculator Simple object-oriented calculator - follow-up Simple object-oriented ...
3
votes
1answer
110 views

Rock, Paper, Scissors, and the Revealing Module Pattern

After reviewing this approach: Rock-Paper-Scissors with the revealing module pattern I decided to write an alternative where the Revealing Module Pattern is used for the UI, model, and controller. I ...
3
votes
2answers
181 views

Lightweight shorthand JS library

Long story short: I wanted some of the time-saving functionality of jQuery without the bulk of the entire library. So, I wrote a lightweight shorthand library inspired by jQuery I'm calling Mozart JS, ...
3
votes
1answer
65 views

Simple JavaScript Module “Loader”

I have written a simple JS module "loader" (loader is in quotes because it doesn't actually load the files) that is designed to resolve simple dependencies between modules. It is heavily inspired by ...
2
votes
1answer
288 views

Truncate text to some number of words when clicked

I am currently using the code below to truncate text: ...
2
votes
2answers
472 views

Genetic Drift simulator

Genetic drift — along with natural selection, mutation, and migration — is one of the basic mechanisms of evolution. In each generation, some individuals may, just by chance, leave behind a few ...
2
votes
2answers
101 views

Range Sum Challenge

I was solving this challenge on the leetcode site. And my runtime is horrible, it beats only 4% of the other solutions. How can I make this better? ...
2
votes
1answer
6k views

Milliseconds to Time string & Time string to Milliseconds

Fast Time conversion I'm trying to write a very fast time-to-string and string-to-time function. I noticed that on low CPU mobile devices this function has, even if minimal, impact on the ...
2
votes
1answer
70 views

Add colour tags on click

I have implemented some extra functionality for the tag-it JavaScript plugin, where I need an option where availableTags are displayed in one box, and the user can ...
2
votes
0answers
27 views

Fast algorithms in Javascript for shortest path queries in directed unweighted graphs - follow-up

(See the previous iteration.) Now I have reworked my pathfinder program, and I ended up with this: ...
2
votes
2answers
121 views

jQuery Tab Scroller

I've never had anyone review my code. I actually found full-time work as a web developer and in the interest of ensuring that I'm always improving, I'd like to see if I'm doing things the proper way. ...
2
votes
2answers
683 views

Infinite scroll for currency list

I made infinite scroll for a currency (in the code below: valute) list. The currency list is fetched via an AJAX-request from a remote server. After it starts the script displays 10 records. After the ...
2
votes
0answers
819 views

Simple clicker game

I have started my clicker game using angular.js about week ago. I have finished current functionality first night, but still have feeling of misunderstanding some basic approaches. This is sources ...
2
votes
3answers
7k views

Remove duplicate values in array with one loop? [closed]

I am writting a program to remove the duplicate values from an array, is any way to optimize code by removing one loop? ...
2
votes
1answer
8k views

jQuery function to link nested checkboxes

...
1
vote
1answer
238 views

Upload and drag the image inside a mask image

I am allowing users to upload and drag images with this code. Give me a review of this. Codepen ...
1
vote
1answer
2k views

jQuery Widget - Progress Tracker

This is a follow up on JS Progress Bar Widget I've rewritten it as a jQuery Widget Factory widget, attempting to follow that standard as much possible and fixing the various problems pointed out in ...
1
vote
2answers
520 views

From an given array of numbers remove duplicate values

I was asked an question for writing a program where the input will be array of numbers; the output of the program will be array of numbers without duplicates. I coded in javaScript which runs on ...
1
vote
1answer
790 views

Parallax animation running well on Chrome but slow on Safari

This is the continuation of a previous question I posted here. I've improved (at least I think so) the initial script from the previous question, now storing the data in an array, it runs slightly ...
0
votes
2answers
243 views

Largest prime factor function

I have written a function which finds the largest prime factor of some number. This function works but the problem is that it is too slow. For instance, when I enter 600851475143 as a parameter, the ...
0
votes
1answer
2k views

Angular version of FitText

This project has evolved a lot since I started learning Angular. I'm pretty happy with it now, and I'm wondering if there's anything I can improve upon, or have forgotten at this point... HTML ...
0
votes
1answer
79 views

Combining hover functions

I have many <spans>s which need to group to change opacity after hover. All of them need to have unique IDs. Is there a way to combine all these hover ...
34
votes
4answers
1k views

Memory with a twist

Description This is the good old game Memory with a twist: Every time you pick a wrong pair, the two tiles you chose will switch their location. So sometimes you might think that a tile is at one ...
13
votes
1answer
284 views

Naming numbers in American English

This seems like a popular topic lately, so I took a crack at it. Related questions are Number to Words and Converting a number to the text representation. I used this article as a guideline. The ...
12
votes
4answers
1k views

Arabic to Greek numeral converter, 1 - 10

One of the things that's straight-forward in JavaScript is Unicode support. If you want to return ϝ (lowercase digamma, not a simple ...
11
votes
4answers
4k views

Codility binary gap solution using regex

Below is the code I implemented to solve the binary gap problem: Find longest sequence of zeros, bounded by ones, in binary representation of an integer. However, it seems to be different from ...
11
votes
1answer
92 views

Improved Sound Control System

After a bit of work, I've changed my code a lot from the previous question: I was recommended by George Mauer and schism to make a better structural design, so hopefully this new build is a bit ...
11
votes
4answers
1k views

Javascript Syntax-Highlighter for Java

Project I wanted to create a syntax highlighter for Java using JavaScript, HTML and CSS. It uses regular expressions to find the parts that should be highlighted (at the moment: keywords, strings, ...
11
votes
1answer
146 views

Wandering water ways

An entry for the August 2016 Community Challenge I slightly modified the input and output to suit the snippet tool, and also because I really like the mapped output with the basins. I have been ...
11
votes
1answer
538 views

node.js Passport Wrapper 2

First attempt was done here: My second attempt (now using jslint to make sure the spacing is correct and have incorporate the majority of the feedback from previous attempt). ...
11
votes
3answers
4k views

Ultimate Tic-Tac-Toe Challenge

This is my attempt at the Ultimate Tic-Tac-Toe code challenge. It uses jQuery to build out the game grid and find the states of all the "buttons" (actually ...
10
votes
1answer
137 views

Script to convert Shift + Spacebar into four spaces on SE

I've posted this feature request and would like to improve the code involved to handle a few "bugs" (not that it's necessary to provide such code, just for my own practice), but I doubt I'm doing it ...
10
votes
2answers
2k views

Optimize/Refactor Javascript Unique Array function

This is one idea of implementation: ...
10
votes
1answer
370 views

Cardshifter login page using vanilla JavaScript

I'm working on rewriting the Cardshifter HTML Client with vanilla JavaScript, the original HTML Client is written with Angular but I really wanted to stay away from anything npm and just go back to ...
10
votes
2answers
75 views

Badge Oneboxer for Chat.SE

This script makes it possible for badges to onebox in Chat. The install requires Tamper/GreaseMonkey. Click here to install, and it's on GitHub and StackApps! ...
10
votes
2answers
168 views

Member list reveals member information on click (#1)

What I'm doing? I'm creating a member-list where initially only the names are visible. Clicking the names reveals the member information. This is done with jQuery by adding/removing classes. I left ...
8
votes
2answers
730 views

The Scripted FizzBuzz Kata

I run a coding dojo at work. for one session I'm to showing that you can use a kata to get into a new language. I'm using the FizzBuzz Kata to show JavaScript (and F#) because it is short. The ...
8
votes
3answers
1k views

HackerRank “Ransom Note” challenge

I have solved the Ransom Note challenge on HackerRank using JavaScript / ECMAScript 6. The challenge goes like this: A kidnapper wrote a ransom note but is worried it will be traced back to him. He ...
8
votes
1answer
145 views

Chart of Percentage questions Answered

Every day, Duga reports the number of unanswered questions and percentage of answered questions (after she calls the API endpoint /info) in The 2nd Monitor (so we ...

1 2 3
4
5
8