Created
February 5, 2021 21:38
-
-
Save sskanishk/e39295f57524ba7ce36b62856cfe10fb to your computer and use it in GitHub Desktop.
Code 1) Deep Clone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clone.js | |
it contaim the deep clone function. | |
Clone.test.js | |
it Contain the test case. | |
Package.json | |
dependencies for JEST. | |
To start | |
node Clone.js | |
To test | |
npm install | |
npm test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const obj = { | |
name: "Paddy", | |
address: { | |
town: "Lerum", | |
country: "Sweden" | |
} | |
} | |
function deepClone(obj) { | |
return {...obj} | |
} | |
// console.log(deepClone(obj)) | |
module.exports = deepClone; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const deepClone = require('./Clone'); | |
test('checking both are same object ', () => { | |
const obj = { | |
name: "Paddy", | |
address: { | |
town: "Lerum", | |
country: "Sweden" | |
} | |
} | |
// checking both are same object | |
expect(deepClone(obj)).toEqual(obj); | |
}); | |
test('checking its clone or not just returning same object', () => { | |
const obj = { | |
name: "Paddy", | |
address: { | |
town: "Lerum", | |
country: "Sweden" | |
} | |
} | |
// checking its clone or not just returning same object | |
expect(deepClone(obj)).not.toBe(obj); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "CloneObject", | |
"version": "1.0.0", | |
"description": "", | |
"main": "Clone.js", | |
"scripts": { | |
"test": "jest --coverage" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"jest": "^26.6.3" | |
} | |
} |
Author
sskanishk
commented
Feb 5, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment