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.
664
questions
3
votes
1
answer
261
views
JS/Node.JS Poem Generator (Followup)
Original question: Node.JS Automatic Poem Generator
This is a followup to the question from above. I am only reposting, as my new code was written from the ground up, and is only slightly similar.
...
6
votes
1
answer
78
views
A node CLI to start new projects
I was annoyed to manually start new projects each time so I made a Node CLI that automate the process. I'm really not comfortable yet with node, so I wanted some advice. It works but I don't know if I ...
8
votes
2
answers
168
views
Functional way to have two toggles that turn each other off
I have two sets of toggles that need to "uncheck" each other. This is my current solution which is working. Can it somehow get more functional/elegant?
...
8
votes
3
answers
684
views
Node.js module using Promises (client for KeePassHttp)
This is my first Node module, as well as the first time using Promises in Javascript. It is a client for the KeePass plugin "KeePassHTTP" to expose passwords securely, which I am planning on using to ...
6
votes
1
answer
370
views
Vanilla ES6 Todo/Task List with LocalStorage
I'm making a simple todo list app with ES6. I'm looking for some feedback on the code, I feel like there is some improvement possible. Maybe there is a better way to attach eventListeners to input and ...
13
votes
1
answer
2k
views
Basic chat server and client using WebSocket
Based on Node.js in Action (Manning Publications) chapter 2 "Building a Multi-room Chat Application", I've taken the model they presented (which is all typical ES5 and jQuery) and completely ...
8
votes
2
answers
505
views
Object-oriented fractal tree
I made an object oriented fractal tree in javascript using the p5 library, it consists of three files:
Fraternal Tree.js
branch.js
flower.js
Here is the github repo with the source code. All the ...
4
votes
1
answer
3k
views
Python like kwargs
I'm delving into JavaScript, and ES6, but want to be able to pass additional options to functions after a spread object.
Coming from Python, you'd just use keyword arguments, such as ...
3
votes
1
answer
5k
views
Codewars "Consecutive strings" kata
The challenge description is as follows:
You are given an array strarr of strings and an integer k. Your task is to return the ...
1
vote
1
answer
42
views
Helper method to check if 3 numbers match some of the valid results
I have this helper method to check if 3 numbers match some of the valid results (XXX+bool, XXX, ...
3
votes
0
answers
86
views
Simple JavaScript MVC implementation
I'm learning to use MVC in my JavaScript apps and I thought it might be good practice to write my own MVC implementation. I'd like to know if you see any ways I could improve it or any potential ...
10
votes
2
answers
252
views
There Was an Old Lady - generate lyrics to a cumulation song
This is a problem from exercism.io. View the repo here (contains full example of song).
Problem statement:
Generate the lyrics of the song 'I Know an Old Lady Who Swallowed a Fly'.
While you could ...
1
vote
1
answer
63
views
Promise Chaining Forgot Password
I have a route I've rewrote to use promises.
...
1
vote
1
answer
864
views
Depth First Search (Adjacency List) in JavaScript
I am trying to implement a DFS search and graphs. How can I make it better?
...
4
votes
1
answer
207
views
Code for finding the "longest" empty space in a grid
I have written some code to find the longest line of empty space in a grid and I'd like to know if it can be simplified or shortened at all.
Here is an example of the input and output of the program:
...
5
votes
2
answers
638
views
99 Bottles of Beer using polymorphism
This was part of an exercise from exercism.io. If you fancy, view the repo here.
Given problem statement:
Write a program which produces the lyrics to that beloved classic, that field-trip ...
1
vote
1
answer
59
views
Complex class polymorphism and lazy-loaded components
I'm having an issue defining a base class and child classes, which handle initialization differently. I want it to work in ES6 but allow babel to transpile to ES5, and currently babel does not have a ...
7
votes
1
answer
531
views
Recursive function to get unique properties
I just wanted to share my newly created JavaScript code. This code is responsible for passing back only the unique elements for a given array. This one is quite useful when you have a huge array and ...
1
vote
1
answer
53
views
Implementation in js to find if N can be written as X ^Y , N<100
From past year ,i have been mainly working on Js, and so have started implementing Algo Questions in js .can it be implemented in a better way.
...
6
votes
1
answer
384
views
Exercise to fetch data from JSON files using ES6 promises
I did an exercise (self-imposed) promise fetching some data from placeholder JSON files on https://jsonplaceholder.typicode.com/. The exercise in my opinion is finished, but I can't shake the feeling ...
2
votes
0
answers
116
views
Creating instances of a logger class for various logging levels
I provide a class to use but for convenience I want the class to implement some instance methods as static methods. This was fast and concise but it feels smelly, probably because I'm modifying the ...
1
vote
2
answers
128
views
Composing a CSS transformation
I have a function that creates a css transform property string
based on some global variables. This string can be copied later by a user, so I would prefer to keep the output short.
This is my code:
...
4
votes
2
answers
162
views
Generate a series of random integers between 1 and 10
Is there a better way of generating a series of unique and random integers between 1 and 10 in JavaScript (ES6)?
...
4
votes
3
answers
2k
views
Get the difference between two dates, in the most convenient unit
I use the following code in Javascript to get the difference between two Date objects. I want the result to return the difference in:
seconds if the result is less than 60 secs
minutes if the result ...
4
votes
1
answer
303
views
Quicksort in JavaScript using destructuring and spread syntax
I'm learning Haskell, and there was quicksort implementation, so I thought that I could implement it in a similar way in JavaScript. The result:
...
4
votes
1
answer
143
views
A JavaScript implementation of the Python's range() function
Recently I implemented the Python's range() function in JavaScript. The function has three parameters: start, ...
1
vote
1
answer
60
views
Create an array which contains specific values of a specific nested object inside an array
So I have this array of objects, which respectively contain other objects:
...
3
votes
1
answer
313
views
Present table of data, acquired from an endpoint, with option to sort by different values
I have built a Vue app which fetches data from an endpoint and presents that data in a table with sortable columns.
The app is based on this React challenge which is to create a table of users and ...
3
votes
1
answer
174
views
Immutable ES7 global state store
I am quite an experienced developer but I am quite new to JS/frontend/functional programming and I am working with react-native in my day-job now.
I'm trying to do my own flux implementation to ...
1
vote
1
answer
254
views
Using Bluebird with fs to read a file within each of an (variable length) array of directories
I'm reading an array (of unknown length) of modules package.json files in order to extract the "style" property and store it in an array of its own:
...
1
vote
0
answers
3k
views
TypingTest Autotyper Userscript
For fun, I decided to inspect the obfuscated source code on TypingTest and figure out how to write an auto typer for it. I came up with the following UserScript.
A couple of notes:
The site's code ...
3
votes
1
answer
108
views
Summarizing and crawling the content of a URL
Lately I've been working on a practice project using JS ES6 to understand it better, therefore I've read a lot about JS design patterns and JS coding strategy. My question is about splitting the ...
3
votes
2
answers
3k
views
SQL LIKE search in Angular filter objects
I made this AngularJS 1.x filter, to search using a the same SQL LIKE syntax. Right now only the percentage symbol (%) is ...
2
votes
2
answers
87
views
Locale language reducer
I am learning redux by doing a small project. Everything is working fine, but I need to know how I can refactor such code. For this situation, it might be good to use ...
4
votes
1
answer
62
views
Getting the three next days
I'm simply getting the 3 future days from an array of objects based on the current day to display for a weather component.
This is the first time I've attempted using ES6 and it's features so please ...
1
vote
1
answer
612
views
Using decorator pattern to validate an entity
I am following this article.
...
4
votes
2
answers
3k
views
Retrieve index of HTML element within parent
I have a function I've been using for years that retrieves the index of an HTML element within its parent element, or, if a second argument is passed to it, the index of an HTML element within the ...
2
votes
0
answers
25
views
Tracking stopped players and connecting them so they can interact
This file handles the player "stopping" in space, trying to find whoever is ahead or behind (also stopped) and joining everyone into each others stopping -rooms. I'm not too sure about the whole "each ...
1
vote
1
answer
66
views
ES6 class that generates an area where you can draw on a page
I have the following javascript es6 class (along with some functions) that generates an area where you can draw in a page.
...
3
votes
1
answer
3k
views
JavaScript Functional Programming Bank Account, Shop and Customer
Motivation
I have worked extensively with JavaScript and have grown fond of some of its functional aspects. This got me wondering how one could implement the canonical example of a bank account - and ...
1
vote
1
answer
67
views
Grouping sub-arrays with nonidentical items
I have a 2D array like
...
3
votes
2
answers
620
views
Plotting JSON locations using Google Road API with Javascript Promise chaining
I wrote this code for an personal application, just to help me visualize some data related to driving. I have one JSON on my machine, this JSON contains a set of locations (lat, lngs) and every ...
3
votes
1
answer
84
views
Handling arguments in a Python-like range() function in JavaScript
I'm making a Python-like range() function (see Python docs) using JavaScript. This function can take from 1 to 3 arguments. There are 3 variables (...
3
votes
0
answers
313
views
Uploading series of large files to API via Node
I wrote a node script to traverse a folder of hour-long mp3s and upload them to Mixcloud via their API. It works, but I suspect it's fairly inefficient - the computer it's going to run on at our radio ...
8
votes
1
answer
2k
views
A box for comments
I made this as a practice application to learn React. It is simply a box where someone can enter their name and a comment and submit it, and display other comments. This animated GIF illustrates what ...
3
votes
0
answers
175
views
ECMAScript 6 amazon lambda image processing
I use this script in amazon lambda for image processing. Script should do:
download image and watermark from amazon S3
resize image to two sizes
put watermark on it and annotate with text
put resized ...
3
votes
2
answers
66
views
Calculate amount of elements in collection by property
I was given this task: Calculate amount of elements in collection by property: "name"
...
1
vote
1
answer
503
views
Singly linked list implementation in JavaScript
I'm looking for feedback on my singly linked list implementation in JavaScript. Please let me know if you have any suggestions on coding style, documentation, bug fixes, etc.
UML / code overview
<...
3
votes
3
answers
328
views
Checking if parentheses are balanced
This script checks if parentheses are balanced. I wonder if there is something that can be improved here including ES6 features.
...
2
votes
1
answer
156
views
Stateless Maximum Beauty of String implementation
Inspired by The Beauty and the Strings question, I tried to implement the "Maximum Beauty of String" in a stateless fashion using ES6. Unfortunately, I ran into two places where I had to assign ...