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
4
votes
1answer
194 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
99 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
169 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 ...
2
votes
1answer
77 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....
6
votes
1answer
115 views

Jest unit test that handles a wrapped Promise

I've wrapped an imported function (a promise) and attempted to write unit tests that bring my codebase to 100% coverage. ...
5
votes
2answers
126 views

Flappy Bird game supporting local multiplayer of up to 2 players

The game is hosted here. GitHub repo This is my first Phaser 3 game/project and I'm still pretty new to Javascript so I'm sure there are many things I could be doing better. The number 1 thing that ...
1
vote
2answers
1k 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
220 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). ...
6
votes
3answers
665 views

My re-written snake game in Javascript

This a snake game I wrote about 1 month ago. It's working well. Looking for any suggestions for my code, I want my coding improved. jsfiddle link http://jsfiddle.net/geswhvdc/ ...
1
vote
2answers
116 views

Show list of numbers 1-10 multiplied by user entered number

Objective of this program is to have the user enter 2 or 9 and output the respective numbers multiple by 2 10 times. Example if a user enters 2, browser will output the following: ...
1
vote
2answers
521 views

Adding and Deleting in ES6 Javascript Alone

I need help in making this as short as possible and it should follow the latest ES6 standards. It it already 100% working. But I need help because i want to follow the best practices in using ES6. The ...
3
votes
2answers
84 views

Robot Return to Origin

The task is taken from leetcode There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes ...
3
votes
1answer
177 views

TamperMonkey Script to replace the YouTube favicon with the channel logo

I felt that having a plain red favicon for every youtube tab is a little boring. So, I wrote a TamperMonkey Script with the new ES6 promises that replaces the favicon with the channel's logo. Link to ...
10
votes
2answers
159 views

String sequence in ES6

Given an unique string that represents a sequence of characters, the class should implement three methods (getNextChar, getNextString and the genSequence generator). How it works We give a sequence ...
1
vote
2answers
53 views

Flipping an Image

The task is taken from leetcode Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image. To flip ...
2
votes
1answer
71 views

Using IndexedDB as an in-browser cache

In my site: Users have many Activities Each Activity has encoded_polyline data I display these encoded_polylines on a map I want to use IndexedDB (via Dexie) as an in-browser cache so that they don'...
3
votes
1answer
126 views

React code to build shopping cart

I have built a basic shopping cart simulator. All it does is add and remove items between two different basket (i.e. aisle vs basket). While working on the problem I started to think about the ...
1
vote
2answers
46 views

Combining arbitrary number of lists inside json

I have some JSON where each key stores an array, and I need to combine all those arrays into a single array. My current solution doesn't seem the most friendly to review, but without ...
3
votes
3answers
102 views

Rotate a linked list to the right by k places

The task Given a linked list and a positive integer k, rotate the list to the right by k places. For example, given the linked list 7 -> 7 -> 3 -> 5 and k = 2, it should become 3 -> 5 -> 7 ...
0
votes
0answers
58 views

Split string into as few substrings as possible such that each substring is a palindrome

The task Given a string, split it into as few strings as possible such that each string is a palindrome. For example, given the input string racecarannakayak, return ["racecar", "anna", "...
2
votes
3answers
92 views

Find non-duplicated integer in a list where every integer occurs three times except for one integer

The task Given an array of integers where every integer occurs three times except for one integer, which only occurs once, find and return the non-duplicated integer. For example, given [6,...
1
vote
1answer
129 views

Sort Array By Parity

The task is taken from leetcode Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A. You may return any ...
2
votes
2answers
99 views

N-Repeated Element in Size 2N Array

The task is taken from leetcode In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times. Return the element repeated N times. ...
4
votes
3answers
780 views

Determine whether an integer is a palindrome

The task Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: ...
0
votes
1answer
37 views

Items also occurs in a set

The task 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 have. You want to know how ...
2
votes
0answers
97 views

Determine whether there exists a one-to-one character mapping from one string to another

The task Determine whether there exists a one-to-one character mapping from one string s1 to another s2. For example, given s1 = abc and s2 = bcd, return true since we can map a to b, b to ...
0
votes
1answer
38 views

Mapping properties between two Objects of different structure

Something I've found myself having to do reasonably often is map properties from an Object (usually a heavily nested MongoDB document) to a different 'shape' to then pass it to a function call or API ...
1
vote
0answers
49 views

JavaScript time series data combination

I've written code that performs a merge of two streams of sorted time series data. The first stream is taken to be the primary and any successive streams are merged into it, using the nearest ...
3
votes
1answer
104 views

Division without using division, multiplication, or modulus operators

The task Implement division of two positive integers without using the division, multiplication, or modulus operators. Return the quotient as an integer, ignoring the remainder. My solution <...
1
vote
2answers
55 views

Sum of two numbers in array

The task You are given two non-empty arrays representing two non-negative integers. The digits are stored in reverse order and each of their items contain a single digit. Add the two numbers ...
1
vote
1answer
147 views

Find busiest period in building

The task You are given a list of data entries that represent entries and exits of groups of people into a building. An entry looks like this: {"timestamp": 1526579928, count: 3, "type": "...
0
votes
1answer
54 views

Find indices of two numbers such that they add up to a target

The task ...is taken from leetcode Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ...
2
votes
2answers
461 views

Web-App for to determine gender, age, emotions of a person (shown on an image)

I have made an app using Microsoft's Face API: Face API JavaScript Quick Start It shall analyze an image, showing a person's portrait, concerning the gender of the person, her/his age and emotions. ...
2
votes
1answer
143 views

User upload & Drag image and update text

I am allowing user to upload images & drag uploaded image once user click on mask images, also gave an option to Edit the text.... I am fetching mask images and text from json file.... I am ...
3
votes
1answer
97 views

AWS Lambda function to update newly added DynamoDB records

Approach All data is submitted into my DynamoDB from another Lambda > API Integration function whereas the lastUpdated row gets inserted as ...
2
votes
0answers
89 views

ReactJS Typewriting animation

One of the dream idea to build typewriting in ReactJS. The code seems to be working, still there are something looks not that great in the code 😔 Looking for better solution (best practice) in the ...
4
votes
1answer
89 views

AutoSuggest: Better way to implement focus after inserting a snippet

Introduction: I am working on a javascript plugin AutoSuggest, My aim is to create an IDE like autocomplete experience in web applications using JavaScript. One of the features I have implemented is ...
4
votes
3answers
92 views

Breaking group of items into rows then ensure consistent height of each row element

I'm working on a product category page where the product images have inconsistent heights so I've been asked to improve the page appearance without changing the images. The page contains x number of ...
2
votes
1answer
360 views

Symfony AJAX comment system with votes

How can I improve this code ? It was quite hard to implement AJAX comment system in Symfony 3, and result is a bit of mess: Controller: ...
1
vote
0answers
55 views

Find the square root of n

The task: Given a real number n, find the square root of n. For example, given n = 9, return 3. My solution: ...
0
votes
1answer
39 views

Extracting grouped objects into a flattened list

I need to optimize this javascript method because it is a bit slow, I don't want to use the flat() command, as for some reason my angular6 app does not understand the vanilla flat() command, or ...
4
votes
2answers
4k views

Flattening multiple nested node readline questions

Say I'm creating a simple CLI. I want to use native node readline module to take in some input from user at prompt. I thought of this: ...
2
votes
2answers
47 views

Optimized pulling items out of arrays in nested objects

I found a couple of similar questions, but they were mostly outdated. Here's the problem: create a flat array from the values in several arrays contained in several nested objects. ...
8
votes
1answer
6k views

My own “Cookie Clicker” Game

I tried to make my own Cookie Clicker Game. It's inspired from this game. Here I just wanted to practice object-oriented programming in JavaScript (and in general) and get experience in game design. ...
2
votes
1answer
54 views

Function to filter comments and ratings, with pagination support

I have a web component that is rendering a list of items and I have this method for filtering these items based in a filterBy object that is being updated by other ...
2
votes
2answers
953 views

Given a set of closed intervals, find the smallest set of numbers that covers all the intervals

The Task: Given a set of closed intervals, find the smallest set of numbers that covers all the intervals. If there are multiple smallest sets, return any of them. For example, given the ...
4
votes
3answers
316 views

Basic orbiting planets in P5.js

I started studying JavaScript about a week ago and I would like some opinions and advice on my code. This program just creates a canvas and instantiates 5 planets that orbit around a sun, giving them ...
4
votes
2answers
91 views

square the elements of a sorted list and give the output in sorted order

Given a sorted list of integers, square the elements and give the output in sorted order. For example, given [-9, -2, 0, 2, 3], return [0, 4, 4, 9, 81]. My solution 1: ...
2
votes
2answers
258 views

Reverse the words in string

The task: Given a string of words delimited by spaces, reverse the words in string. For example, given "hello world here", return "here world hello" Follow-up: given a mutable string ...