Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix typos and syntax errors (#307)
Co-authored-by: Nam Hoang Le <nam.hoang.le@mgm-tp.com>
  • Loading branch information
nam-hle and Nam Hoang Le committed May 19, 2021
1 parent 2d3174c commit 4b2f1da
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 38 deletions.
34 changes: 17 additions & 17 deletions README.md
Expand Up @@ -8,7 +8,7 @@ You are welcome to contribute with more items provided below.

* If you are targeting legacy JavaScript engine with those ES5 methods, you can use [es5-shim](https://github.com/es-shims/es5-shim)

* Please note that, the examples used below are just showing you the native alternative of performing certain tasks. For some of the functions, Lodash provides you more options than native built-ins. This list is not a 1:1 comparison.
* Please note that, the examples used below are just showing you the native alternative of performing certain tasks. For some functions, Lodash provides you more options than native built-ins. This list is not a 1:1 comparison.

* Please send a PR if you want to add or modify the code. No need to open an issue unless it's something big and you want to discuss.

Expand Down Expand Up @@ -1028,7 +1028,7 @@ Returns everything but the last entry of the array. Pass n to exclude the last n

// Native
var array = [5, 4, 3, 2, 1]
console.log(array.slice(0, -2););
console.log(array.slice(0, -2));
// output: [5, 4, 3]
```

Expand Down Expand Up @@ -1273,9 +1273,9 @@ Creates an object composed of keys generated from the results of running each el
// Lodash
console.log(_.keyBy(['a', 'b', 'c']))
// output: { a: 'a', b: 'b', c: 'c' }
console.log(_.keyBy([{ id: 'a1', title: 'abc' }, { id: 'b2', title: 'def' }], 'id')
console.log(_.keyBy([{ id: 'a1', title: 'abc' }, { id: 'b2', title: 'def' }], 'id'))
// output: { a1: { id: 'a1', title: 'abc' }, b2: { id: 'b2', title: 'def' } }
console.log(_.keyBy({ data: { id: 'a1', title: 'abc' }}, 'id')
console.log(_.keyBy({ data: { id: 'a1', title: 'abc' }}, 'id'))
// output: { a1: { id: 'a1', title: 'abc' }}

// keyBy for array only
Expand All @@ -1284,9 +1284,9 @@ Creates an object composed of keys generated from the results of running each el
// Native
console.log(keyBy(['a', 'b', 'c']))
// output: { a: 'a', b: 'b', c: 'c' }
console.log(keyBy([{ id: 'a1', title: 'abc' }, { id: 'b2', title: 'def' }], 'id')
console.log(keyBy([{ id: 'a1', title: 'abc' }, { id: 'b2', title: 'def' }], 'id'))
// output: { a1: { id: 'a1', title: 'abc' }, b2: { id: 'b2', title: 'def' } }
console.log(keyBy(Object.values({ data: { id: 'a1', title: 'abc' }}), 'id')
console.log(keyBy(Object.values({ data: { id: 'a1', title: 'abc' }}), 'id'))
// output: { a1: { id: 'a1', title: 'abc' }}

// keyBy for array and object
Expand Down Expand Up @@ -1983,29 +1983,29 @@ Checks if value is an empty object or collection.

```js
// Lodash
console.log(_.isEmpty(null)
console.log(_.isEmpty(null))
// output: true
console.log(_.isEmpty('')
console.log(_.isEmpty(''))
// output: true
console.log(_.isEmpty({})
console.log(_.isEmpty({}))
// output: true
console.log(_.isEmpty([])
console.log(_.isEmpty([]))
// output: true
console.log(_.isEmpty({a: '1'})
console.log(_.isEmpty({a: '1'}))
// output: false

// Native
const isEmpty = obj => [Object, Array].includes((obj || {}).constructor) && !Object.entries((obj || {})).length;

console.log(isEmpty(null)
console.log(isEmpty(null))
// output: true
console.log(isEmpty('')
console.log(isEmpty(''))
// output: true
console.log(isEmpty({})
console.log(isEmpty({}))
// output: true
console.log(isEmpty([])
console.log(isEmpty([]))
// output: true
console.log(isEmpty({a: '1'})
console.log(isEmpty({a: '1'}))
// output: false
```

Expand Down Expand Up @@ -2332,7 +2332,7 @@ Checks if `key` is a direct property of `object`. Key may be a path of a value s
### _.get

Gets the value at path of object.
*Note: If provided path does not exists inside the object js will generate error.*
*Note: If provided path does not exist inside the object js will generate error.*

```js
// Lodash
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/all.js
Expand Up @@ -8,7 +8,7 @@ const ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 2018, sourceType: "module" }
});

// Only a couple of smoke tests because otherwise it would get very reduntant
// Only a couple of smoke tests because otherwise it would get very redundant

ruleTester.run('_.concat', rules.concat, {
valid: [
Expand Down
35 changes: 15 additions & 20 deletions tests/unit/all.js
Expand Up @@ -15,8 +15,8 @@ describe('code snippet example', () => {
const lodashArray = [1]
const lodashResult = _.concat(lodashArray, 2, [3], [[4]])

const nativehArray = [1]
const nativeResult = nativehArray.concat(2, [3], [[4]])
const nativeArray = [1]
const nativeResult = nativeArray.concat(2, [3], [[4]])

assert.deepEqual(lodashResult, nativeResult)
})
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('code snippet example', () => {
"kk.ll": { "mm.n": [3, 4, { "oo.p": 5 }] }
};

it ("should handle falsey values", () => {
it ("should handle falsy values", () => {
var val = _.get(obj, 'aa[0].b.c', 1)
assert.strictEqual(val, get(obj, 'aa[0].b.c', 1))
assert.notEqual(val, 1)
Expand Down Expand Up @@ -354,49 +354,49 @@ describe('code snippet example', () => {
}
return (num >= Math.min(init, final) && num < Math.max(init, final));
}

it('_.inRange(3, 2, 4)', () => {
assert.equal(
_.inRange(3, 2, 4),
inRange(3, 2, 4)
)
});

it('_.inRange(4, 8)', () => {
assert.equal(
_.inRange(4, 8),
inRange(4, 8)
)
});

it('_.inRange(4, 2)', () => {
assert.equal(
_.inRange(4, 2),
inRange(4, 2)
)
});

it('_.inRange(2, 2)', () => {
assert.equal(
_.inRange(2, 2),
inRange(2, 2)
)
});

it('_.inRange(1.2, 2)', () => {
assert.equal(
_.inRange(1.2, 2),
inRange(1.2, 2)
)
});

it('_.inRange(5.2, 4)', () => {
assert.equal(
_.inRange(5.2, 4),
inRange(5.2, 4)
)
});

it('_.inRange(-3, -2, -6)', () => {
assert.equal(
_.inRange(-3, -2, -6),
Expand Down Expand Up @@ -574,11 +574,11 @@ describe('code snippet example', () => {
assert.deepStrictEqual(randoms, [100000, 100001]);
});
});

describe('clamp', () => {
const clamp = (number, boundOne, boundTwo) => {
if (!boundTwo) {
return Math.max(number, boundOne) === boundOne ? number : boundOne;
return Math.max(number, boundOne) === boundOne ? number : boundOne;
} else if (Math.min(number, boundOne) === number) {
return boundOne;
} else if (Math.max(number, boundTwo) === number) {
Expand Down Expand Up @@ -683,7 +683,7 @@ describe('code snippet example', () => {
describe('isUndefined', () => {
const definedVariable = 1; //defined variable (will return false)
let undefinedVariable; //undefined variable (will return true)

it('_.isUndefined(definedVariable)', () => {
assert.equal(_.isUndefined(definedVariable),
(definedVariable === undefined))
Expand Down Expand Up @@ -725,7 +725,7 @@ describe('code snippet example', () => {
describe('forEach', () => {
it('_.forEach(array)', () => {
const testArray = [1,2,3,4];

let lodashOutput = []
let nativeOutput = []

Expand Down Expand Up @@ -828,13 +828,9 @@ describe('code snippet example', () => {
});
})


describe('isFunction', () => {
function isFunction(func) {
if (func && typeof func === "function") {
return true
}
return false
return (func && typeof func === "function")
}

it('_.isFunction(setTimeout)', () => {
Expand All @@ -852,6 +848,5 @@ describe('code snippet example', () => {
isFunction("abc"))
});


});
});

0 comments on commit 4b2f1da

Please sign in to comment.