Fix test cases

This commit is contained in:
Stefan Feješ
2017-12-17 22:26:07 +01:00
parent e87678f359
commit 82b850fd00
20 changed files with 21 additions and 21 deletions

View File

@ -9,5 +9,5 @@ const JSONToDate = arr => {
const dt = new Date(parseInt(arr.toString().substr(6))); const dt = new Date(parseInt(arr.toString().substr(6)));
return `${ dt.getDate() }/${ dt.getMonth() + 1 }/${ dt.getFullYear() }` return `${ dt.getDate() }/${ dt.getMonth() + 1 }/${ dt.getFullYear() }`
}; };
// jsonToDate(/Date(1489525200000)/) -> "14/3/2017" // JSONToDate(/Date(1489525200000)/) -> "14/3/2017"
``` ```

View File

@ -7,5 +7,5 @@ Use `fs.writeFile()`, template literals and `JSON.stringify()` to write a `json`
```js ```js
const fs = require('fs'); const fs = require('fs');
const JSONToFile = (obj, filename) => fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2)) const JSONToFile = (obj, filename) => fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2))
// jsonToFile({test: "is passed"}, 'testJsonFile') -> writes the object to 'testJsonFile.json' // JSONToFile({test: "is passed"}, 'testJsonFile') -> writes the object to 'testJsonFile.json'
``` ```

View File

@ -6,5 +6,5 @@ Convert given RGB parameters to hexadecimal string using bitwise left-shift oper
```js ```js
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0'); const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
// rgbToHex(255, 165, 1) -> 'ffa501' // RGBToHex(255, 165, 1) -> 'ffa501'
``` ```

View File

@ -9,5 +9,5 @@ const UUIDGenerator = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
); );
// uuid() -> '7982fcfe-5721-4632-bede-6000885be57d' // UUIDGenerator() -> '7982fcfe-5721-4632-bede-6000885be57d'
``` ```

View File

@ -6,5 +6,5 @@ Use `Array.reduce()` to add each value to an accumulator, initialized with a val
```js ```js
const arrayAverage = arr => arr.reduce((acc, val) => acc + val, 0) / arr.length; const arrayAverage = arr => arr.reduce((acc, val) => acc + val, 0) / arr.length;
// average([1,2,3]) -> 2 // arrayAverage([1,2,3]) -> 2
``` ```

View File

@ -6,5 +6,5 @@ Use `Array.reduce()` to add each value to an accumulator, initialized with a val
```js ```js
const arraySum = arr => arr.reduce((acc, val) => acc + val, 0); const arraySum = arr => arr.reduce((acc, val) => acc + val, 0);
// sum([1,2,3,4]) -> 10 // arraySum([1,2,3,4]) -> 10
``` ```

View File

@ -16,7 +16,7 @@ const cleanObj = (obj, keysToKeep = [], childIndicator) => {
}) })
} }
/* /*
testObj = {a: 1, b: 2, children: {a: 1, b: 2}} const testObj = {a: 1, b: 2, children: {a: 1, b: 2}}
cleanObj(testObj, ["a"],"children") cleanObj(testObj, ["a"],"children")
console.log(testObj)// { a: 1, children : { a: 1}} console.log(testObj)// { a: 1, children : { a: 1}}
*/ */

View File

@ -6,5 +6,5 @@ Use ES6 `Set` and the `...rest` operator to discard all duplicated values.
```js ```js
const distinctValuesOfArray = arr => [...new Set(arr)]; const distinctValuesOfArray = arr => [...new Set(arr)];
// unique([1,2,2,3,4,4,5]) -> [1,2,3,4,5] // distinctValuesOfArray([1,2,2,3,4,4,5]) -> [1,2,3,4,5]
``` ```

View File

@ -6,5 +6,5 @@ Use `Array.filter()` to create a new array that contains every nth element of a
```js ```js
const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === 0); const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === 0);
// everynth([1,2,3,4,5,6], 2) -> [ 1, 3, 5 ] // everyNth([1,2,3,4,5,6], 2) -> [ 1, 3, 5 ]
``` ```

View File

@ -7,6 +7,6 @@ Use `Array.map()`, `split()` and `Array.join()` to join the mapped array for con
```js ```js
const extendHex = shortHex => const extendHex = shortHex =>
'#' + shortHex.slice(shortHex.startsWith('#') ? 1 : 0).split('').map(x => x+x).join('') '#' + shortHex.slice(shortHex.startsWith('#') ? 1 : 0).split('').map(x => x+x).join('')
// convertHex('#03f') -> '#0033ff' // extendHex('#03f') -> '#0033ff'
// convertHex('05a') -> '#0055aa' // extendHex('05a') -> '#0055aa'
``` ```

View File

@ -9,5 +9,5 @@ You can omit `el` to use a default value of `window`.
const getScrollPosition = (el = window) => const getScrollPosition = (el = window) =>
({x: (el.pageXOffset !== undefined) ? el.pageXOffset : el.scrollLeft, ({x: (el.pageXOffset !== undefined) ? el.pageXOffset : el.scrollLeft,
y: (el.pageYOffset !== undefined) ? el.pageYOffset : el.scrollTop}); y: (el.pageYOffset !== undefined) ? el.pageYOffset : el.scrollTop});
// getScrollPos() -> {x: 0, y: 200} // getScrollPosition() -> {x: 0, y: 200}
``` ```

View File

@ -10,5 +10,5 @@ const getURLParameters = url =>
url.match(/([^?=&]+)(=([^&]*))/g).reduce( url.match(/([^?=&]+)(=([^&]*))/g).reduce(
(a, v) => (a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1), a), {} (a, v) => (a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1), a), {}
); );
// getUrlParameters('http://url.com/page?name=Adam&surname=Smith') -> {name: 'Adam', surname: 'Smith'} // getURLParameters('http://url.com/page?name=Adam&surname=Smith') -> {name: 'Adam', surname: 'Smith'}
``` ```

View File

@ -8,5 +8,5 @@ You can omit `start` to use a default value of `0`.
```js ```js
const initializeArrayWithRange = (end, start = 0) => const initializeArrayWithRange = (end, start = 0) =>
Array.from({ length: end - start }).map((v, i) => i + start); Array.from({ length: end - start }).map((v, i) => i + start);
// initializeArrayRange(5) -> [0,1,2,3,4] // initializeArrayWithRange(5) -> [0,1,2,3,4]
``` ```

View File

@ -7,5 +7,5 @@ You can omit `value` to use a default value of `0`.
```js ```js
const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value); const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value);
// initializeArray(5, 2) -> [2,2,2,2,2] // initializeArrayWithValues(5, 2) -> [2,2,2,2,2]
``` ```

View File

@ -10,7 +10,7 @@ const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)
/* /*
const add5 = x => x + 5 const add5 = x => x + 5
const multiply = (x, y) => x * y const multiply = (x, y) => x * y
const multiplyAndAdd5 = pipe(multiply, add5) const multiplyAndAdd5 = pipeFunctions(multiply, add5)
multiplyAndAdd5(5, 2) -> 15 multiplyAndAdd5(5, 2) -> 15
*/ */
``` ```

View File

@ -6,5 +6,5 @@ Use `Math.random()` to generate a random value, map it to the desired range usin
```js ```js
const randomNumberInRange = (min, max) => Math.random() * (max - min) + min; const randomNumberInRange = (min, max) => Math.random() * (max - min) + min;
// randomInRange(2,10) -> 6.0211363285087005 // randomNumberInRange(2,10) -> 6.0211363285087005
``` ```

View File

@ -15,7 +15,7 @@ const readFileLines = filename => fs.readFileSync(filename).toString('UTF8').spl
line2 line2
line3 line3
___________________________ ___________________________
let arr = readFileToArray('test.txt') let arr = readFileLines('test.txt')
console.log(arr) // -> ['line1', 'line2', 'line3'] console.log(arr) // -> ['line1', 'line2', 'line3']
*/ */
``` ```

View File

@ -7,5 +7,5 @@ Use `Array.reduce()` to create a promise chain, where each promise returns the n
```js ```js
const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve()); const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve());
// const delay = (d) => new Promise(r => setTimeout(r, d)) // const delay = (d) => new Promise(r => setTimeout(r, d))
// series([() => delay(1000), () => delay(2000)]) -> executes each promise sequentially, taking a total of 3 seconds to complete // runPromisesInSeries([() => delay(1000), () => delay(2000)]) -> executes each promise sequentially, taking a total of 3 seconds to complete
``` ```

View File

@ -13,5 +13,5 @@ const speechSynthesis = message => {
msg.voice = window.speechSynthesis.getVoices()[0]; msg.voice = window.speechSynthesis.getVoices()[0];
window.speechSynthesis.speak(msg); window.speechSynthesis.speak(msg);
}; };
// speak('Hello, World') -> plays the message // speechSynthesis('Hello, World') -> plays the message
``` ```

View File

@ -8,5 +8,5 @@ Return the string truncated to the desired length, with `...` appended to the en
```js ```js
const truncateString = (str, num) => const truncateString = (str, num) =>
str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str; str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;
// truncate('boomerang', 7) -> 'boom...' // truncateString('boomerang', 7) -> 'boom...'
``` ```