Похожие чаты

I am rewriting some methods of lodash because I am

learning FP stuffs. I was rewriting implementation of _.drop https://lodash.com/docs/4.17.15#drop

export const drop = (array: unknown[], n = 1) => array.slice(n);

I have written something like above snippet and I found why I really need drop? It's doing same thing as .slice but when I check lodash source code they have written something differently

https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L4045

I am just curious why they have written almost 20 lines of code if they can do using .slice()
also, why they have written _.drop since .slice will do same thing

6 ответов

22 просмотра
decoder- Автор вопроса

get more context from here

decoder- Автор вопроса

I thought may be they have written this method because slice not supported older browsers but I see almost all browsers are supports

there is no fun with that. got to wrap JavaScript with more JavaScript to enjoy life

Cause it's doing a lot more than just running the function. It needs to check if all the parameters are okay, make sure you didn't pass through an empty array, check the size, check if the value even fits in the array, make sure you're working with a positive value if you pass through a negative, etc. If you know that your data is gonna be clean and it can't be anything else than what you provide then just pass it through slice for a performance gain instead of relying on the checks c:

J : Vaccinated 🇨🇦
Cause it's doing a lot more than just running the ...

I understand using the library is a personal/teams choice. But why not follow the single responsibility principle (unwritten rule)¿? similar to unix philosophy

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта