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...
-
2You can use the javascript functionsantosh singh– santosh singh2018-01-26 20:45:52 +00:00Commented Jan 26, 2018 at 20:45
-
1Typescript is a wrapper around ALL javascript. You're only coding in javascript.SoEzPz– SoEzPz2018-01-26 21:01:41 +00:00Commented Jan 26, 2018 at 21:01
-
You could also leverage Observables for this as shown here: stackoverflow.com/questions/41961982/…DeborahK– DeborahK2018-01-26 21:39:30 +00:00Commented Jan 26, 2018 at 21:39
-
Thank you so much for the help :)niraja k– niraja k2018-01-29 13:56:35 +00:00Commented Jan 29, 2018 at 13:56
Add a comment
|
2 Answers
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;});