title: have_same_contents
tags: list,intermediate

Returns True if two lists contain the same elements regardless of order, False otherwise.

Use set() on the combination of both lists to find the unique values.
Iterate over them with a for loop comparing the count() of each unique value in each list.
Return False if the counts do not match for any element, True otherwise.

继续阅读 30秒学会 Python 片段 – have_same_contents.md

Vertically and horizontally centers a child element within its parent element using position: absolute and transform: translate() (as an alternative to flexbox or display: table).
Similar to flexbox, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.

  • position: absolute on the child element allows it to be positioned based on its containing block.
  • left: 50% and top: 50% offsets the child 50% from the left and top edge of its containing block.
  • transform: translate(-50%, -50%) allows the height and width of the child element to be negated so that it is vertically and horizontally centered.
  • Note that the fixed height and width on parent element is for the demo only.

继续阅读 30秒学会 CSS 片段 – Transform centering

Removes elements in an array until the passed function returns true. Returns the removed elements.

Loop through the array, using a for...of loop over Array.prototype.entries() until the returned value from the function is true.
Return the removed elements, using Array.prototype.slice().

继续阅读 30秒学会 JavaScript 片段 – takeWhile

Removes elements from the end of an array until the passed function returns true. Returns the removed elements.

Loop through the array, using a Array.prototype.reduceRight() and accumulating elements while the function returns falsy value.

继续阅读 30秒学会 JavaScript 片段 – takeRightWhile