Questions tagged [ecmascript-6]

ECMAScript 6 reached feature complete status in 2014. The features vary widely from completely new objects and patterns to syntax changes to new methods on existing objects.

Filter by
Sorted by
Tagged with
0
votes
1answer
14 views

Loading KML files into leaflet Javascript map

This is working code for input KML files into leaflet map ...
8
votes
3answers
617 views

Weapon class firing logic in JavaScript

I'm making a program to compare Borderlands 3 weapon damage over time in a graphic. There's still some work to be done, like implementing elemental damage, but I'd like to know if I'm doing a good job ...
1
vote
0answers
20 views

Promise-based AJAX calls base class

I am more than willing to use both a Promise library and an AJAX calls one if the situation calls for it. This base class sits at the very bare bones of my system and it needs to be done right. My ...
4
votes
2answers
98 views

An ES6 array of numbers - Double last number, delete the first number

I'm writing a JavaScript function for an array, based on a geographic sequence. \$[1, 2, 4, 8, 16]\$, etc. This function needs to populate the next number in the sequence $$item_n = item_{n-1} * ...
7
votes
2answers
132 views
+50

eCommerce Mockup App in JS

I have completed this mockup eCommerce app using Javascript. This version can add products into a shopping cart and automatically calculate the order summary in the shopping cart. It can also delete ...
6
votes
1answer
96 views

Simple input class change with vanilla JS

I am just testing how I solved simple stuff. Goal: The aim is to expand the width of an input and collapse it. When mouseover ...
3
votes
2answers
61 views

A basic trivia app

The app grabs 10 questions from an API, displays them one by one with 4 multiple choice answers. These answers are clickable buttons that alert to whether the answer is correct or not. Finally the ...
1
vote
1answer
47 views

Flattening the nested Objects

The original idea behind the problem is that the API I'm working with returns one type of a response for GET, and requires another type to do ...
4
votes
1answer
40 views

JavaScript HTML DatePicker

I'm still new in javascript and learning. I want to create a date picker using html and javascript. Below is what I have tried and it's working, so my question is "how can I do it better?" My idea is ...
8
votes
5answers
727 views

Expanding powers of expressions of the form ax+b

I solved the following problem: Write a function expand that takes in an expresion with a single, one character variable, and expands it. The expresion is in the form ...
1
vote
1answer
52 views

Finding the objects with the cheapest seats

i have the following json object ...
3
votes
2answers
60 views

Sort, slice and rebuild new object with array data

I'm using the matomo reports api to pull out some data in js. For some charts, I'm in the need to sort the array data based on inner property value ("val"), further to get only the 3 highest (Hong ...
0
votes
0answers
21 views

Multiple animation control using Vanilla JS ES6

What I'm doing Divide members into five section, and apply animation for each member to reveal at first. When I click the section, it is expanded to whole viewport and introduce detail about ...
4
votes
1answer
57 views

Event triggers for animations using vanilla ES6

I'm new to JS and wanna know right code style or approach to cod Vanilla JS using ES6. To practice this, I'm using ESLint JS code-style of AirBnb and referencing clean-code-javascript repo. However, I ...
0
votes
0answers
37 views

How to filter URL from the array list based on the string name with regExp?

The solution found to filtering pathname with customising current normalizeTme() function. For sure it is not the ideal way of ...
4
votes
2answers
65 views

An Express route, which renders a page, and makes use of socket.io

This is the code for a basic endpoint in my express app routes folder. This firstly renders a page, and then on a continuous loop, renders information about some random "Breaking Bad" character. The ...
4
votes
1answer
71 views

Pivotting SQL Table Response to JSON in JavaScript

Issue Our API returns two formats JSON and this SQL table format. I'm not sure what it is truly called so I'll give a few examples below. Like all API responses, it can be a list or a single response ...
4
votes
1answer
104 views

Pulling data from the GitHub API for user repositories

I'm looking for specific feedback on a major design change that I plan on making to my personal website (https://aleksandrhovhannisyan.github.io/). Currently, the Projects section contains hardcoded ...
4
votes
1answer
50 views

Triggering a callback when user put in the Konami cheat code anywhere in the page

I wrote this just for some fun and also to practise my ES6 skills. When user key in the Konami Cheat Code(⬆️⬆️⬇️⬇️⬅️➡️⬅️➡️🅱️🅰️↩️) anywhere in the page, it should trigger a callback. In the following ...
0
votes
0answers
24 views

Details/Dropdown toggler

I haven't had a great deal of time to build components using some of the more fun items that have come since ES6+ started hitting the scene, but figured I'd share a dropdown snippet I created and get ...
4
votes
2answers
72 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
3answers
47 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 ...
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
0answers
60 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. ...
3
votes
1answer
57 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
121 views

Merge Intervals in JavaScript

This task is taken from Leetcode - Given a collection of intervals, merge all overlapping intervals. Example 1: ...
2
votes
3answers
75 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 ...
2
votes
1answer
53 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 ...
2
votes
1answer
65 views

Length of the longest consecutive run of 1s in its binary representation

The task Given an integer n, return the length of the longest consecutive run of 1s in its binary representation. For example, given 156, you should return 3 My function solution 1 Style 1 ...
4
votes
2answers
69 views

Static site generator using JavaScript Promises

I have created a small static site generator (for learning purposes) in Javascript ES6, using Promises, but I am not certain of how to use them well. The code below works fine, but I wonder if i can't ...
3
votes
1answer
59 views

Longest Consecutive Sequence

This task is taken from Leetcode - Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Your algorithm should run in \$O(n)\$ complexity. ...
1
vote
1answer
37 views

Daily Temperatures

The task is taken from leetcode Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer ...
4
votes
1answer
101 views

Encode and Decode TinyURL

The task is taken from leetcode TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl....
1
vote
2answers
93 views

Find out whether number is of Power of Two

The task is taken from leetcode Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 Output: true Explanation: 20 = 1 Example 2: ...
1
vote
1answer
52 views

Reverse Vowels of a String

The task is taken from leetcode Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Input: "hello" Output: "holle" Example 2: ...
3
votes
2answers
69 views

Add one to the last array element

The task is taken from leetcode Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is ...
3
votes
1answer
54 views

Addition of Strings

The task is taken from leetcode Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < ...
20
votes
4answers
4k views

Count all vowels in string

For a homework assignemnt, I was asked to complete this CodeStepByStep problem. It's coded correctly and gave me a right answer. I'm just wondering if there's an easier way to solve this problem ...
1
vote
2answers
80 views

First Unique Character in a String

The task is taken from leetcode Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return ...
2
votes
2answers
68 views

Find All Numbers Disappeared in an Array

The task is taken from leetcode Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] ...
4
votes
1answer
160 views

Island Perimeter

The task is taken from leetcode You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically ...
2
votes
1answer
71 views

Find Median of Two Sorted Arrays in JS

The task is taken from leetcode There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should ...
4
votes
2answers
106 views

Create a min stack

The task is taken from leetcode Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes ...
6
votes
1answer
126 views

Given a string containing just parentheses, determine if the input string is valid

The task is taken from leetcode Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: ...
2
votes
1answer
65 views

Unique Email Addresses

The task was taken from leetcode Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode.com, alice is the local name, and leetcode....
5
votes
1answer
86 views

Container with most water

The task is taken from leetcode Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of ...
4
votes
3answers
164 views

Reverse Integer

The task is taken from leetcode Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: ...
1
vote
2answers
689 views

Longest Substring Without Repeating Characters in JS

The task is taken from leetcode Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: ...
1
vote
3answers
79 views

Add Two Numbers

The task is taken from leetcode You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single ...
1
vote
1answer
118 views

Find common characters (LeetCode)

The task is taken from leetcode Given an array A of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). ...