Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Abdullah Bin Asad #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions javascript_solution.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
const json = require('./tests/challenge.json');


function is_number(val) {
return val.match("(\d+(\.\d+)?)");
}

function parse_object(data) {
if (Array.isArray(data)) {
for (let i = 0; i < data.length; i++) {
if (is_number(data[i])) {
data[i] = parseFloat(data[i]);
}
}
return data;

} else if (typeof data === 'string') {
if (is_number(data)) {
return parseFloat(data);
} else if (data === 'true') {
data = true;
} else if (data === 'false') {
data = false;
}
return data;
} else {
let keys = Object.keys(data);
for (let key of keys) {
data[key] = parse_object(data[key])
}
}
return data;
}

const refineParameters = data => {
// Write your code here.
// Remember to call this function to return the formatted json
// with the json imported at the top of this file

// Run this file with `node javascript_solution.js` in your CLI to verify your answer

return parse_object(data)
}




// Comment out the line below to console.log and call your function to debug
// console.log('formattedJson: ', refineParameters(json));

// ----- Do not modify anything below this line (needed for test suite) ------
module.exports = refineParameters;

console.log(refineParameters(json))
Loading