Returns the target value in a nested JSON object, based on the given key.

Use the in operator to check if target exists in obj.
If found, return the value of obj[target], otherwise use Object.values(obj) and Array.prototype.reduce() to recursively call dig on each nested object until the first matching key/value pair is found.

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

Vertically and horizontally centers a child element within its parent element using display: table (as an alternative to flexbox).

  • display: table on ‘.center’ allows the element to behave like a <table> HTML element.
  • 100% height and width on ‘.center’ allows the element to fill the available space within its parent element.
  • display: table-cell on ‘.center > span’ allows the element to behave like an <td> HTML element.
  • text-align: center on ‘.center > span’ centers the child element horizontally.
  • vertical-align: middle on ‘.center > span’ centers the child element vertically.
  • The outer parent (‘.container’ in this case) must have a fixed height and width.

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

Pads a string on both sides with the specified character, if it’s shorter than the specified length.

Use String.prototype.padStart() and String.prototype.padEnd() to pad both sides of the given string.
Omit the third argument, char, to use the whitespace character as the default padding character.

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

Returns true if at least one element in the collection passes the test implemented by the provided function, false otherwise.

Implement an appropriate function for each type.
Use range to iterate over elements in the given collection, returning true or false based on the result of fn.
The functions can be tweaked to allow for an index to be passed to fn as a second argument, if desired.

继续阅读 30秒学会 Golang 片段 – Any

Converts a string to snake case.

Use String.replaceAllMapped() to break the string into words and String.toLowerCase() to convert each one to lowercase, using a RegExp.
Use String.replaceAll() to replace invalid separator characters (- and spaces) with underscores.

继续阅读 30秒学会 Dart 片段 – toSnakeCase

Returns a map with the unique values of a list as keys and their frequencies as the values.

Use Iterable.toSet() to get the unique values of the list.
Use Map.fromIterable(), Iterable.where() and Iterable.length to generate a map with the unique values as keys and their frequencies as values.

继续阅读 30秒学会 Dart 片段 – frequencies