Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let data = [[1,2,[3]],4];
- Array.prototype.isNormalized = function(){
- for(let item of this)
- if(typeof item === "object")
- return false
- return true;
- }
- Array.prototype.normalize = function() {
- let output = [];
- for(let item of this) {
- if(typeof item !== "object") {
- output.push(item);
- }
- else {
- if (!item.isNormalized()) {
- item = item.normalize();
- }
- output.push(...item)
- }
- }
- return output;
- }
- let flatArray = data.normalize();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement