Questions tagged [typescript]

Typescript is a language which is a super set of JavaScript

Filter by
Sorted by
Tagged with
41 votes
8 answers
25k views

Deck of cards as an interview exercise

I was asked to write a test code for an exercise for a job I applied for. I was rejected, and I didn't know why. And I want to ask your opinions about my code. The exercise is like that: Write a ...
Sam Smith's user avatar
  • 521
16 votes
3 answers
67k views

Filtering undefined elements out of an array

I have some code that filters an array with type (Suggestion|undefined)[] into an array with type Suggestion[], but I feel it ...
Drew's user avatar
  • 373
14 votes
2 answers
358 views

Emulation of SE's text input control for tags

Introduction I used React to write a component, which is meant to be a faithful emulation of the input for "Tags" which you see at the top of every question/topic on SE. Why this project? If you're ...
ChrisW's user avatar
  • 12.9k
13 votes
3 answers
3k views

Wrapping IndexDB with RxJs

I find IndexedDB cumbersome and want to wrap the functionality with rxjs observables. I've come up with an angular2 service that seems to fit the bill, but I'm wondering if I'm using the observables ...
Jason Goemaat's user avatar
11 votes
1 answer
25k views

Angular 2 clock with RxJS Observable

I'm fairly new to Angular 2 and I started off with creating a clock for my app. I tried to stick to the official documentation tutorial. Folder structure: The CSS file is still empty and the HTML is ...
OddDev's user avatar
  • 411
11 votes
2 answers
28k views

RxJS Observable with initial value

Is it possible to get rid of the BehaviourSubject to have an Observable with an initial value? Another thing I don't like is that I'm using getValue() and then modify this value and push it with next ...
seveves's user avatar
  • 403
10 votes
1 answer
559 views

Javascript/Typescript anagram String search

I've created a random word generator which allows me to create random words/anagrams. Then I've created Anagram search app to find the angarams when user start typing in inbox. Could you review ...
MonteCristo's user avatar
10 votes
1 answer
546 views

Lightweight Angular tooltip component

I made a small Popup component to show different error/success...etc. messages. Template: ...
Embrioka's user avatar
  • 313
10 votes
1 answer
574 views

Checkers Board Creator

A year or so ago, I wrote a checkers game for the Universal Windows Platform. Now, I wrote a web-based version of it hosted at http://checkerstreasury.azurewebsites.net. This is the first of a series ...
user avatar
9 votes
4 answers
2k views

JavaScript function that flips brackets direction

I have these strings: )hello( this has ]some text[ flip }any{ brackets even with )))]multiple[((( brackets As you can see, the brackets are all in the wrong ...
Elron's user avatar
  • 203
9 votes
4 answers
5k views

Returning the last segment of a split string

I recently reviewed a PR and saw the following. const parts = someString.split('.'); return parts[parts.length - 1]; was changed to ...
Willi Mentzel's user avatar
9 votes
1 answer
29k views

Angular directive to disable a button when clicked, allowing re-enabling as needed

I have written an Angular Directive that disables a button after it has been clicked, to prevent double posting / saving of data. This works fine in most of our use cases. However, in some situation ...
Daan's user avatar
  • 191
9 votes
1 answer
5k views

Factory method done on ReactJS component

A Factory Pattern or Factory Method Pattern says that just define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate. In other words, ...
Luis Valencia's user avatar
9 votes
3 answers
8k views

Modal component in Angular 2

I've recently started to check out Angular 2 and TypeScript that comes with it, and I guess I'm kinda into it. However I'm not too sure about the whole "TypeScript way" of doing things, specifically ...
Chrillewoodz's user avatar
8 votes
2 answers
242 views

JSON4 parser in Typescript

Context I may have accidentally gotten a little sidetracked during homeschooling, and wrote a JSON4 parser in Typescript during the down-time. This project started as an idea that I got while ...
Patrick Hollweck's user avatar
8 votes
2 answers
1k views

Piano, output all the keys and give a scale

I've two snippets below, the first one output all the keys of a piano and the second one give me a scale when given a starting note. For those who don't know how a piano is structured here is an image ...
Ced's user avatar
  • 199
8 votes
1 answer
7k views

Angular 5 Forms - Extending Form Control

I am taking a first pass at Angular Forms with some colleagues and noticed an interesting design pattern implemented by a coworker where the FormControl is being ...
The Pax Bisonica's user avatar
7 votes
3 answers
1k views

Counting words from stored .md files

The following searches recursively for all the mark down files - i. ending with the extension .md - inside a folder. It then stores the text of the files in an ...
wyc's user avatar
  • 565
7 votes
3 answers
180 views

Find the fastest run of each year from a list of running results

Problem Explained: Imagine there is a list of running results of 1000m, like following: ...
Yi Zeng's user avatar
  • 181
7 votes
1 answer
844 views

Random generator extension for VSCode

Background A VSCode extension that uses Chance.JS to generate random data types. Concerns My main concern is that there are 4 levels of function references that feels like a hack. From ...
Helix Quar's user avatar
7 votes
2 answers
325 views

Accounting for floating point error when rounding

I have to implement some business logic that will round a number (typically a double) upwards. Given that this number comes from a third-party and I don't know how they come to calculate it I'm ...
HexedAgain's user avatar
6 votes
1 answer
21k views

Parallel and Sequential array looping with async/await

Are these good implementations of parallel and sequential "extension" methods, and do they accomplish what I think they do? My understanding is that the first one is parallel because the await ...
Dave Cousineau's user avatar
6 votes
1 answer
78 views

Code Refactoring for Dynamic List in Angular 8

With a specific requirement of showing/hiding the pages, the following implementation has been carried out. The pages which needs to be hidden will be provided through an array ...
rams's user avatar
  • 163
6 votes
2 answers
3k views

Angular control for inputting latitude and longitude with validation

I've built a custom control to handle user input in a human-readable format, but save in a machine-format. It needs to have input validation, and to convert UI-input to a base format. I'm interested ...
ANeves's user avatar
  • 2,882
6 votes
1 answer
6k views

Iterating through nested array of objects

I have the following JSON list of objects, and I'm able to find the required object, and pass it back to the caller, given the id. Everything works fine, I'm just ...
Ruaghain's user avatar
6 votes
1 answer
13k views

Audio player in Angular 2

I just built an audio player in Angular 2 using a player component and a player service. It's all working fine, I just feel like there is a much better way to do this. Should the audio object be in ...
Matt Thomas's user avatar
6 votes
1 answer
2k views

Alarm Clock with React.js

Preamble This is an Alarm Clock app. The way it works is pretty simple: you change the time by pressing the +/- buttons and set the time by pressing the play button. When the time is up, the alarm ...
bzrr's user avatar
  • 209
6 votes
1 answer
3k views

Custom RxJS operator to prevent duplicate API calls in Angular

I have a usecase where I want to prevent unexpected duplicate Http calls. I'm wondering if I can have a custom operator which can be used in pipe for any API as shown in below ...
knowhow's user avatar
  • 61
6 votes
1 answer
739 views

State Monad in TypeScript

Here's my implementation of State Monad in TypeScript, based on a canonical Haskell implementation. I would like it to get code reviewed. ...
dark_ruby's user avatar
  • 193
6 votes
1 answer
187 views

Angular component for a system to store student test scores

I am designing a system and in it there is a view where teachers can see a summary of test data on students. Here is the component of it: ...
Mr V's user avatar
  • 71
5 votes
2 answers
474 views

Prettier Pug Plugin

I'm the creator of the plugin Prettier Pug Plugin. Everything works fine and I have a lot of tests because I used TDD I currently have a large index.ts (permalink). In this file mainly an array of ...
Shinigami's user avatar
  • 215
5 votes
1 answer
436 views

Best Practices Generics in Typescript

I'm wondering and actually playing in typescript playground with generics functions. The question is, is the code below readable? If not what kind of approach I could use to make it more typescript ...
drocha87's user avatar
  • 153
5 votes
3 answers
3k views

Poker Holdem Hand Evaluation 7 cards to 5

I'm building a poker Hold'em hand evaluator. Ultimately my goal after building the evaluator is to build a client on the browser but that's far from now. What I've done so far is a hand analyzer that ...
Ced's user avatar
  • 199
5 votes
1 answer
2k views

Natural sorting/comparing algorithm in TypeScript

This code sorts string that may contain numbers in natural order, that's it, "item 2" comes before than "item 10". It currently ignores case. I plan to implement options to handle case sensitivity and ...
André Werlang's user avatar
5 votes
1 answer
373 views

Roman Number to Integer

Problem Definition Roman numerals are represented by seven different symbols: I, V, X, <...
Igor Soloydenko's user avatar
5 votes
2 answers
177 views

Managing Angular subscriptions

There are different methods to get data from server in Angular application: Get Observable from the service and subscribe to it at component Create Subject at the service and subscribe to the Subject ...
Nikita's user avatar
  • 153
5 votes
4 answers
5k views

Cracking the Coding Interview: "Problem 1.5. One Away"

I am going one-by-one through problems in the "Cracking the Coding Interview". This question is about problem 1.5. One Away. Since I was never good in "algorithming", any suggestions are highly ...
Igor Soloydenko's user avatar
5 votes
1 answer
295 views

Most compact data format for a shopping cart

I'm trying to build a format that can represent the user's cart on my website in the most compact way. The website is related to computer parts and there are 23 product categories. Each product has an ...
Raees Iqbal's user avatar
5 votes
1 answer
70 views

getting inferences working with typescript pubsubber

So I'm learning typescript and I'm making a simple functional PubSub system. I want the user to be able to define topics and the data for those topics. So far I've got the below code, but I really ...
Adam Jenkins's user avatar
5 votes
1 answer
213 views

React hook: useAsyncValue

I wrote this little hook so I could fetch some remote resources: ...
mpen's user avatar
  • 201
5 votes
2 answers
130 views

Make JSON based on available fields

I am trying to create a filter string according to the fields available with the following code, how could i improve the following with a switch case or better way? ...
Sajeetharan's user avatar
5 votes
1 answer
189 views

Zork look-a-like written in TypeScript

I've been working on a a text based game with a very simple battling system. There are way to many questions I can ask to get reviewed about this project, but I'll take small steps at a time (this is ...
Federlizer's user avatar
5 votes
1 answer
157 views

Typescript monad for data being loaded

I have been struggling to make typescript happy about the types. I am pulling data from our backend API and I wanted to give context to the data. Basically it is a monad with 4 shapes: Initial (...
Mehdi Saffar's user avatar
5 votes
1 answer
9k views

Filtering objects according to required and preferred attributes

This my opportunity object which is a part of my angular app.component.ts file. In my template(HTML of this component) I want to ...
Yashwardhan Pauranik's user avatar
5 votes
1 answer
5k views

Making multiple http request Angular2

I need to get some ids from contacts and contactgroups to be able to collect the data. My example works but i dont know if this is the way to go. ...
Payt's user avatar
  • 51
5 votes
1 answer
413 views

BitBoard class In TypeScript for chess logic

I'm working on writing a Chess Logic Library in JavaScript for learning purposes and was wondering how good these two slightly different implementations of a BitBoard are. The first stores the board ...
casual234's user avatar
  • 152
5 votes
4 answers
68 views

Calculating total size of player data

I am writing a function to calculate the total size of a "player appearance". There are various "item slots" the player has, and if they are empty then 1 byte will be sent, otherwise there will be 2. ...
James Monger's user avatar
5 votes
1 answer
1k views

Parse big JSON for reactive form

I implements big reactive form on angular5. This form get data from JSON. I use formBuilder and several nested formGroups. Every field have default value before rendering form. In console output form ...
cyklop77's user avatar
  • 311
5 votes
1 answer
2k views

TypeScript definitions for Server-Sent Events

I could not find any definitions of the EventSource object that belongs to Server-Sent Events, so I create the definitions. That's how they look like: ...
yankee's user avatar
  • 498
5 votes
0 answers
150 views

Hutton cipher implemented using recursive functions

Is there a way to rewrite these last 2 recursive functions with fewer arguments (preferably 2) while keeping them recursive? The entire code can be seen here: https://github.com/GirkovArpa/hutton-...
GirkovArpa's user avatar

1
2 3 4 5
11