-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlookupTable.js
More file actions
32 lines (28 loc) · 1.22 KB
/
lookupTable.js
File metadata and controls
32 lines (28 loc) · 1.22 KB
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
26
27
28
29
30
31
32
// generate e lookup label
const posts = [
{ id: "A123", title: "Learn JavaScript Basics", author: "Rahim" },
{ id: "B456", title: "Understanding ES6 Features", author: "Karim" },
{ id: "C789", title: "Intro to React", author: "Amina" },
{ id: "D234", title: "Advanced React Hooks", author: "Sakib" },
{ id: "E567", title: "CSS Flexbox Guide", author: "Nusrat" },
{ id: "F890", title: "Mastering CSS Grid", author: "Tanvir" },
{ id: "G345", title: "Node.js for Beginners", author: "Hasan" },
{ id: "H678", title: "Express.js Crash Course", author: "Jahid" },
{ id: "I901", title: "MongoDB Basics", author: "Mim" },
{ id: "J112", title: "Full Stack Development Guide", author: "Arif" },
];
const lookupTable = posts.reduce((table, post) => {
// console.log("First Table data :", table);
// console.log("First post data :", post);
table[post.id] = post;
return table;
}, {});
// console.time("postFindTimeComplex");
// const post = posts.find((post) => post.id === "J112");
// console.timeEnd("postFindTimeComplex");
// console.log(post);
console.time("reduceFunctionToComplex");
const post = lookupTable["J112"];
console.timeEnd("reduceFunctionToComplex");
console.log(post);
// console.log("Lookup table :", lookupTable);