DEV Community

Leticia Amancio
Leticia Amancio

Posted on

Codes for daily life

This post is in construction, i wanna increase more codes that i use in my day by day.

Remove Duplicate Elements

Recently, i needed to group by identical products and sum your prices that received in list. First, i remove duplicate product id and then i group by id.

To remove duplicates values, do this:

`const removeDuplicates = (arr) => [...new Set(arr)];

const productsId = ["17", "27", "17", "40"];

removeDuplicates(productsId); // ['17', '27', '40']
`

Uppercase first letter

Who has never needed put first letter in uppercase to show in page, do this:

const capitalize = (str) => ${str.charAt(0).toUpperCase()}${str.slice(1)};

......

Updates will be coming soon

Top comments (0)