Skip to main content
39 votes

Deck of cards as an interview exercise

No one but the folks who reviewed your code for the company can say with certainty why you were rejected. It also depends on the position you're applying for. If you're applying for an entry-level ...
Chris G's user avatar
  • 501
28 votes

Deck of cards as an interview exercise

This is mostly how I would solve it (in Python): ...
Zah's user avatar
  • 450
26 votes
Accepted

Deck of cards as an interview exercise

While not strictly required, we value usage instructions, nicely-modeled data, automated tests, and thoughtful consideration of architectural decisions and simplicity-vs-completeness trade-offs. ...
Joseph's user avatar
  • 25.1k
23 votes
Accepted

Filtering undefined elements out of an array

To be using strict null checks, you must be on "typescript": "^2.0.0". Thus, my example will be using this version of typescript with ...
CAD97's user avatar
  • 1,944
22 votes

Filtering undefined elements out of an array

Typescript 1.6 introduced user defined type guards that are a function whose return type is a boolean that is cast as a type predicate. To define a simple isString ...
Richard Johnson's user avatar
14 votes

Filtering undefined elements out of an array

Building on @RichardJohnson's answer: why not write one function that can filter any array of possibly-undefined values? Let's make it generic. ...
Adam's user avatar
  • 241
13 votes

Returning the last segment of a split string

I'm not entirely enthusiastic about either. The parts[parts.length - 1] using manual index lookup and subtraction may well take a moment to recognize, "Oh, ...
CertainPerformance's user avatar
11 votes

Assistance requested to refactor a section of Typescript code for readability

To make it easier to follow the flow of the logic, I'm just going to pull out the longer parts of these conditions into helper variables. They may not stay like that in the final version, but it helps ...
Scotty Jamison's user avatar
10 votes

Deck of cards as an interview exercise

I sympathise :) I'm not sure if my answer will actually help much as it's either a rant or a list of hard work to do but hopefully it informs. Interview tests are hopelessly flawed experiments When ...
Seth's user avatar
  • 209
9 votes
Accepted

Angular 2 clock with RxJS Observable

Your service looks perfectly fine to me. As far as the Clock component goes, I can only recommend one thing. When ...
Igor Soloydenko's user avatar
9 votes

Returning the last segment of a split string

tl;dr at the end. In terms of 'performance', js engines are pretty well optimized. For something like this, performance should not be part of your argument against a given piece of code. In terms of ...
santanaG's user avatar
  • 403
9 votes

Counting words from stored .md files

How to modify this code, so it doesn't use forEach? One way to achieve this is using Array.prototype.reduce(): ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
8 votes

JavaScript function that flips brackets direction

It may seem unlikely but it is not impossible for an input string to contain tempBracket so a solution that doesn't involve adding and replacing that string would ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
8 votes

Counting words from stored .md files

Another suggestion: with TypeScript, you only need to note the type of a parameter when TypeScript can't infer it itself. You might find it easier to read and write code when you avoid explicitly ...
CertainPerformance's user avatar
7 votes
Accepted

Emulating constructor overloading in Typescript

A few of thoughts: You don't need to declare types for the arguments in the implementation of your constructor, just the overloads (which precede the implementation). I wouldn't use a separate object ...
Burt_Harris's user avatar
7 votes

TypeScript Dictionary class

Edit: I've updated the code and uploaded a gist that will work in the TS playground - the gist will compile with Typescript 3.1. The primary benefit of Typescript is to provide types for Javascript. ...
Sean Newell's user avatar
7 votes

toggle boolean with if statement

Value flipping is traditionally just done with a negation: this.showAllOnlineFriends = !this.showAllOnlineFriends That is a common, good practice way to do it. It ...
rolfl's user avatar
  • 97.4k
6 votes
Accepted

Parallel and Sequential array looping with async/await

JavaScript's execution model My understanding is that the first one is parallel because the await applies to each invocation of the async lambda that is passed to map. This is not quite right ...
ComFreek's user avatar
  • 751
6 votes
Accepted

code duplication in conditional Promise

You could move the door.locked check into the door.unlock() function (or into a new function) which would allow you return a promise for both cases: ...
Murray's user avatar
  • 198
6 votes
Accepted

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

First solution using .forEach, for...in and .sort Here what I did to achieve this: First ...
Ivan's user avatar
  • 450
6 votes

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

One of the main ways in which you can improve this is by using Renderer2 in the directive instead of directly accessing this.el.nativeElement and making changes to ...
SiddAjmera's user avatar
6 votes

JavaScript function that flips brackets direction

This is an answer that I posted to the original question on StackOverflow. It does away with regular expressions entirely, and uses a similar case-statement to the one suggested in @Henrik's answer ...
tucuxi's user avatar
  • 307
6 votes
Accepted

Best Practices Generics in Typescript

Your code looks quite reasonable, though there are a few tweaks you could consider. Function or Callback? Rather than names like FoldlFunction and ...
CertainPerformance's user avatar
6 votes
Accepted

JSON4 parser in Typescript

All in all, this is some well-written, well-structured and well-typed code. I like it! I do have a few nitpicks, though: The type of ScalarNode.type might be a bit ...
Sara J's user avatar
  • 3,479
5 votes

Wrapping IndexDB with RxJs

updated version of the code, based on @MarcoTerzolo 's answer ...
Yvonne Aburrow's user avatar
5 votes

RxJS Observable with initial value

This is a really good question -- starred it! I am not very experienced with RxJs, but I believe your code around BehaviorSubject and ...
Igor Soloydenko's user avatar
5 votes
Accepted

Find the most common number in an array of numbers

For small arrays as input your script's performance is very good. Let me show you a different approach which might especially improve readability and might also increase performance for larger inputs ...
insertusernamehere's user avatar
5 votes
Accepted

Converting Object to Map using Generics

A few points first. Avoid any like the plague. You can nearly always figure out a better type. When dealing with a JSON serialized data, I like to have a function ...
Gerrit0's user avatar
  • 3,456
5 votes
Accepted

Angular service for fetching and passing data with observables

One of the improvements would be to use an HttpClient instead of Http for making the API calls. If you use ...
SiddAjmera's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible