-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (31 loc) · 1.07 KB
/
index.js
File metadata and controls
36 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
/* eslint-disable guard-for-in */
const jsonValueReplacer = (obj, val) => {
const modifiedObj = {};
for (const key in obj) {
modifiedObj[key] = (typeof obj[key] === 'object') ? jsonValueReplacer(obj[key], val) : val;
}
return modifiedObj;
};
const shuffleString = str => {
return str.split('').sort(() => {
return 0.8 - Math.random();
}).join('');
};
const jsonValueReplacerShuffle = obj => {
const modifiedObj = {};
for (const key in obj) {
modifiedObj[key] = (typeof obj[key] === 'object') ? jsonValueReplacerShuffle(obj[key]) : shuffleString(obj[key]);
}
return modifiedObj;
};
const jsonValueReplacerSameLength = (obj, val) => {
const modifiedObj = {};
for (const key in obj) {
modifiedObj[key] = (typeof obj[key] === 'object') ? jsonValueReplacerSameLength(obj[key], val) : val.repeat(obj[key].length);
}
return modifiedObj;
};
module.exports = (obj, val) => jsonValueReplacer(obj, val);
module.exports.shuffle = obj => jsonValueReplacerShuffle(obj);
module.exports.sameLength = (obj, val) => jsonValueReplacerSameLength(obj, val);