Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Nov 3, 2019

No description provided.

// Use Array.prototype.reduce of for loop
};
const ipToInt = (ip = '127.0.0.1') => ip.split('.').reduce(
(sum, elem, i, arr) => sum + (Number(elem) << 8 * (arr.length - 1 - i))
Copy link

@avtohem avtohem Nov 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shifts a in binary representation b (< 32) bits to the left, shifting in 0s from the right.
Если массив будет больше 4 элементов, то не сработает.. хотя к IPv4 это не относится...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants