Похожие чаты

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 ответов

19 просмотров
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

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

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

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
15
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
13
any reference of this implementation?
BitBuddha
29
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
&"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\dumpbin.exe" /EXPORTS C:\Users\Yeet\Tauon\vcpkg\installed\x64-window...
Martin Rys
6
Карта сайта