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
77
votes
6answers
7k views

You hate h̶a̶t̶s̶ reputation? Click here to get rid of it

Soo... I recently read a meta-post about the inherent problems of reputation. It listed some things like: Confirmation bias. Demotivating for low-rep users. Hubris and elitism of high-rep users over ...
6
votes
1answer
75 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: ...
4
votes
1answer
70 views

<select multiple> with dropdown

I wanted to use <select multiple> but was annoyed by the poor design on desktops which is why I created a version with dropdown: ...
9
votes
2answers
86 views

Fetching movie data using jQuery

Requirements Display movie datas inside all tags that have the class movie_list Make an ajax call for fetching movie datas Fill loading text before fetch data If any error occurs during loading, the ...
2
votes
0answers
72 views

Angular 1 CSS Encapsulation

I am trying to get a good clean way to do CSS Encapsulation in Angular JS. The main goal of this is to use isolated components. This is what I have come up with so far. The method I am using is ...
3
votes
1answer
44 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
100 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 ...
1
vote
1answer
97 views

Manipulating arrays to extract unique objects and count occurrences

The data describes cycling activities (key1) and chunks of them (key2). In total there are around 1,000 ...
4
votes
1answer
47 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 ...
6
votes
1answer
128 views

3D 1st Person Snake Game #3

Final iteration of an iterative review. The previous iteration is here: 3D 1st Person Snake Game #2 Note: For the snippet, click run, "Full page", purposely lose, and then type r. Here is the ...
3
votes
1answer
52 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 ...
0
votes
0answers
23 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 ...
5
votes
1answer
344 views

JavaScript module to render and handle a form to add users

I recently switched to modular JavaScript and really like the idea of having the state of your application in JavaScript and not in the DOM. I want to know if what I am doing is considered best ...
2
votes
1answer
77 views

Find all pairs of unique indices in a list such that the concatenation of the two words is a palindrome

The task Given a list of words, find all pairs of unique indices such that the concatenation of the two words is a palindrome. For example, given the list ...
3
votes
3answers
45 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 ...
4
votes
2answers
70 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 ...
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 ...
4
votes
1answer
104 views

UpvoteJS, a simple voting widget in vanilla JavaScript

I implemented a simple voting widget like the one used on Stack Exchange sites, to use for other purposes (see live on bashoneliners.com), as a reusable package, dubbed UpvoteJS. Here's how it works: ...
3
votes
1answer
101 views

Display and search through a JSON's items in Vue.js

I have put together this small application that displays a "Users" JSON in an HTML5 table. I use Bootstrap 3, Axios and Vue.js 2 for this purpose. Here is the code: ...
0
votes
0answers
50 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. ...
4
votes
2answers
1k views

If non-array property exists convert it to one and push new value

Is there a simpler/shorter/better way to do this? ...
7
votes
1answer
173 views

Interactive small town

I've built this simple interactive scenario. Now everything seems working fine except that when start for loop as below. What can I do to make the script faster? ...
3
votes
1answer
56 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. ...
4
votes
0answers
87 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
64 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 ...
4
votes
3answers
138 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: ...
2
votes
1answer
43 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 ...
5
votes
1answer
81 views

Advent Of Code 2017 Day 4 (part 2) in Functional Programming (FP)

I wanted to practice functional programming (FP) without using any library but using vanilla JavaScript only. So I took a problem from Advent of Code (the 2nd part of Day 4) You can only access the ...
5
votes
1answer
106 views

Passing a callback to a component in Vue.js

I'm currently trying to teach myself Vue.js and I've just created my first small project: a simple todo list. While writing the component I discovered that you can't access methods from the parent ...
6
votes
1answer
188 views

Simple color clicker game

My friend recently made a color clicker game, and I tried cleaning up the code a bit. I want to know how I can improve the functions and passing/editing of global variables. There are a lot of ...
4
votes
1answer
90 views

JavaScript canvas Snake game

This is my 3rd JavaScript canvas game. It's basically just snake right now but I am planning on adding some more aspects to it soon. I was wondering if I could get some feedback especially on how I'm ...
2
votes
1answer
56 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
66 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 ...
1
vote
1answer
32 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 ...
1
vote
1answer
79 views

UserScript to Highlight tab for queue item

It may seem a bit obsessive and/or pedantic, but the following script allows me to see when posts are ready for reviewing. I developed this UserScript for use with TamperMonkey to allow me to have a ...
20
votes
4answers
3k 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 ...
2
votes
1answer
94 views

React Component Design

Building out a React component that is supposed to hold the following information and display it in a feed-like page. The idea is to later map over the individual entries in an array. Author ...
4
votes
1answer
77 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
87 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
41 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: ...
5
votes
1answer
79 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 ...
3
votes
1answer
53 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 < ...
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
2answers
89 views

Mean by properties in array of objects

I have this array of objects: ...
1
vote
1answer
95 views

Find all starting indices in a string which are anagrams of a word

The task: Given a word W and a string S, find all starting indices in S which are anagrams of W. For example, given that W is "ab", and S is "abxaba", return 0, 3, and 4. My solution: ...
1
vote
2answers
79 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 ...
3
votes
1answer
52 views

Building a unique array of db fields

This is stripped down from a project I'm working on: ...
2
votes
2answers
56 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
141 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
55 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 ...