Build, resolve #172

This commit is contained in:
Angelos Chalaris
2017-12-16 17:19:16 +02:00
parent d34d32b1b2
commit b55b684931
5 changed files with 39 additions and 4 deletions

View File

@ -29,6 +29,7 @@ Here's what you can do to help:
- Try to keep your snippets' code short and to the point. Use modern techniques and features. Make sure to test your code before submitting. - Try to keep your snippets' code short and to the point. Use modern techniques and features. Make sure to test your code before submitting.
- All snippets must be followed by one (more if necessary) test case after the code, on a new line, in the form of a comment, along with the expected output. The syntax for this is `myFunction('testInput') -> 'testOutput'`. Use multiline comments only if necessary. - All snippets must be followed by one (more if necessary) test case after the code, on a new line, in the form of a comment, along with the expected output. The syntax for this is `myFunction('testInput') -> 'testOutput'`. Use multiline comments only if necessary.
- Try to make your function name unique, so that it does not conflict with existing snippets. - Try to make your function name unique, so that it does not conflict with existing snippets.
- Snippet functions do not have to handle errors in input, unless it's necessary (e.g. a mathematical function that cannot be extended to negative numbers should handle negative input appropriately).
- Snippets should be short (usually below 10 lines). If your snippet is longer than that, you can still submit it, and we can help you shorten it or figure out ways to improve it. - Snippets should be short (usually below 10 lines). If your snippet is longer than that, you can still submit it, and we can help you shorten it or figure out ways to improve it.
- Snippets *should* solve real-world problems, no matter how simple. - Snippets *should* solve real-world problems, no matter how simple.
- Snippets *should* be abstract enough to be applied to different scenarios. - Snippets *should* be abstract enough to be applied to different scenarios.

View File

@ -101,6 +101,8 @@
* [Capitalize first letter of every word](#capitalize-first-letter-of-every-word) * [Capitalize first letter of every word](#capitalize-first-letter-of-every-word)
* [Capitalize first letter](#capitalize-first-letter) * [Capitalize first letter](#capitalize-first-letter)
* [Check for palindrome](#check-for-palindrome) * [Check for palindrome](#check-for-palindrome)
* [Convert string from camelcase](#convert-string-from-camelcase)
* [Convert string to camelcase](#convert-string-to-camelcase)
* [Reverse a string](#reverse-a-string) * [Reverse a string](#reverse-a-string)
* [Sort characters in string (alphabetical)](#sort-characters-in-string-alphabetical) * [Sort characters in string (alphabetical)](#sort-characters-in-string-alphabetical)
* [Truncate a string](#truncate-a-string) * [Truncate a string](#truncate-a-string)
@ -175,7 +177,7 @@ const remove = (arr, func) =>
arr.splice(arr.indexOf(val), 1); return acc.concat(val); arr.splice(arr.indexOf(val), 1); return acc.concat(val);
}, []) }, [])
: []; : [];
//remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4] // remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4]
``` ```
[⬆ back to top](#table-of-contents) [⬆ back to top](#table-of-contents)
@ -1152,6 +1154,37 @@ const palindrome = str => {
[⬆ back to top](#table-of-contents) [⬆ back to top](#table-of-contents)
### Convert string from camelcase
Use `replace()` to remove underscores, hyphens and spaces and convert words to camelcase.
Omit the scond argument to use a default separator of '_'.
```js
const fromCamelCase = (str, separator = '_') =>
str.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2')
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2').toLowerCase();
// decamelize('someDatabaseFieldName', ' ') -> 'some database field name'
// decamelize('someLabelThatNeedsToBeCamelized', '-') -> 'some-label-that-needs-to-be-camelized'
// decamelize('someJavascriptProperty', '_') -> 'some_javascript_property'
```
[⬆ back to top](#table-of-contents)
### Convert string to camelcase
Use `replace()` to remove underscores, hyphens and spaces and convert words to camelcase.
```js
const toCamelCase = str =>
str.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2, offset) => p2 ? p2.toUpperCase() : p1.toLowerCase());
// camelize("some_database_field_name") -> 'someDatabaseFieldName'
// camelize("Some label that needs to be camelized") -> 'someLabelThatNeedsToBeCamelized'
// camelize("some-javascript-property") -> 'someJavascriptProperty'
// camelize("some-mixed_string with spaces_underscores-and-hyphens") -> 'someMixedStringWithSpacesUnderscoresAndHyphens'
```
[⬆ back to top](#table-of-contents)
### Reverse a string ### Reverse a string
Use array destructuring and `Array.reverse()` to reverse the order of the characters in the string. Use array destructuring and `Array.reverse()` to reverse the order of the characters in the string.

View File

@ -1,6 +1,7 @@
/* /*
This is the linter script that lints snippets. This is the linter script that lints snippets.
Run using `npm run linter`. Run using `npm run linter`.
You might have to run `npm i -g semistandard` for this script to run properly.
*/ */
// Load modules // Load modules
const fs = require('fs-extra'), cp = require('child_process'), path = require('path'), chalk = require('chalk'); const fs = require('fs-extra'), cp = require('child_process'), path = require('path'), chalk = require('chalk');

View File

@ -9,5 +9,5 @@ const remove = (arr, func) =>
arr.splice(arr.indexOf(val), 1); return acc.concat(val); arr.splice(arr.indexOf(val), 1); return acc.concat(val);
}, []) }, [])
: []; : [];
//remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4] // remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4]
``` ```

View File

@ -10,7 +10,6 @@ array-without:array
array-zip:array array-zip:array
average-of-array-of-numbers:array average-of-array-of-numbers:array
bottom-visible:browser bottom-visible:browser
convert-string-to-camelcase:string
capitalize-first-letter-of-every-word:string capitalize-first-letter-of-every-word:string
capitalize-first-letter:string capitalize-first-letter:string
chain-asynchronous-functions:function chain-asynchronous-functions:function
@ -20,10 +19,11 @@ clean-JSON-object:object
collatz-algorithm:math collatz-algorithm:math
compact:array compact:array
compose-functions:function compose-functions:function
convert-string-from-camelcase:string
convert-string-to-camelcase:string
count-occurrences-of-a-value-in-array:array count-occurrences-of-a-value-in-array:array
current-URL:browser current-URL:browser
curry:function curry:function
convert-string-from-camelcase:string
deep-flatten-array:array deep-flatten-array:array
distance-between-two-points:math distance-between-two-points:math
divisible-by-number:math divisible-by-number:math