Here is the interview question prompt, presented for reference.
Imagine a universe of data types in JavaScript! It's a colorful world with characters like Array, ArrayBuffer, Map, Set, Date, and the mysterious Function. Your mission, should you choose to accept it, is to create a universal method that identifies these inhabitants by their data type name.
Constraints:
- The function should take only one argument—the data object.
- We want a universal approach; using multiple if conditions to list and detect each data type is a no-go.
For the function detectType(), the following should hold true:
detectType(1); // Output: 'number'
detectType(new Map()); // Output: 'map'
detectType([]); // Output: 'array'
detectType(null); // Output: 'null'
You can see the full challenge with visuals at this link.
Challenges • Asked over 4 years ago by Team AlgoDaily
This is the main discussion thread generated for Get Data Type (Main Thread).