-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathT3Q0.js
25 lines (16 loc) · 847 Bytes
/
T3Q0.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* Question 00
Convert a given object into an array of arrays.
Given an object, create an array which contains arrays with the key/value pairs.
To keep this simple, the values will only be primitive types (number, string, etc.) and not other objects or array.
Furthermore, assume that the input is always clean/accurate. In other words, don't worry about handling edge cases.
Examples
- objectToArray({ a: 1, b: 2, c: 3 })
=> [['a', 1], ['b', 2], ['c', 3]]
- objectToArray({name: 'Dave', role: 'Instructor', yearsOfExperience: 10})
=> [['name', 'Dave'], ['role', 'Instructor'], ['yearsOfExperience', 10]]
*/
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
const objectToArray = function (obj) {
return Object.entries(obj);
};
console.log(objectToArray({ a: 1, b: 2, c: 3 }));