0

I am new to TypeScripting and would like to know how to find distinct numbers from a array of numbers. Can I use the same functions as that in JavaScript in the filter function in Typescript or is there a different way. Thanks...

4
  • 2
    You can use the javascript function Commented Jan 26, 2018 at 20:45
  • 1
    Typescript is a wrapper around ALL javascript. You're only coding in javascript. Commented Jan 26, 2018 at 21:01
  • You could also leverage Observables for this as shown here: stackoverflow.com/questions/41961982/… Commented Jan 26, 2018 at 21:39
  • Thank you so much for the help :) Commented Jan 29, 2018 at 13:56

2 Answers 2

0

was able to work it out using js functions

Sign up to request clarification or add additional context in comments.

Comments

0

An old post but posting anyways, so that anyone seeking help might land here and use this solution. So let's say we have a complex array and it has an element "OntheElementToDoDistinct" and we wish to get distinct values of it.

let distinctArray = array.filter((thing, i, arr) => {
return arr.indexOf(arr.find(t => t.OntheElementToDoDistinct === 
thing.OntheElementToDoDistinct )) === i;});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.