From c6205bf62e5ddca5fbd071508cc1389d387522b6 Mon Sep 17 00:00:00 2001 From: Jan Halfar Date: Thu, 20 Jan 2022 18:18:54 +0100 Subject: [PATCH] added language to docblocks --- foomo/docs/frontend/performance.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/foomo/docs/frontend/performance.md b/foomo/docs/frontend/performance.md index 9f80349..626cb0e 100644 --- a/foomo/docs/frontend/performance.md +++ b/foomo/docs/frontend/performance.md @@ -9,16 +9,18 @@ sidebar_position: 4 JS is nowadays extremely fast and yet we have many performance issues. Here you can find few common mistakes that occur in JS that can decrease performance. ### Extensive use of .map, .filter + Let's say you have a large list of objects and you would like to filter them and transform them in some form. Usually we do this: -``` +```JavaScript const largeArray = [ .... ] largeArray.map(obj => transformObj(obj)).filter(omitBadObject) ``` In the above case we first loop through whole set, transform it and then filter things out. Not only does this goes through all the items twice, but it also first time goes through all the items and then filters them. One optimization would be to first filter them and then transform them, but ideally we should just use a normal for loop or forEach where you go through items only once. -``` + +```JavaScript const finalArray = [] largeArray.forEach(obj => { if (omitBadObject(obj)) { @@ -26,4 +28,5 @@ largeArray.forEach(obj => { } }) ``` -This code will skip another loop of items. \ No newline at end of file + +This code will skip another loop of items.