Hi I need to make jsut a quick prototype function for JSON mystringify:
/*
Implement function myStringify that takes in an object and returns a string
Input:
{
x: 5,
y: 6,
student: {
a: "apple",
b: "banana"
}
}
Output: '{"x":5,"y":6,"student":{"a":"apple","b":"banana"}}'
*/
Exmaple like this:
Array.prototype.myMap = function(func){
let newArray = [] //creating a new array
for (let i = 0; i < this.length;="" i++)="">
const result = func(this[I], I);//applying a callback to each element and store it in the result
newArray.push(result); //we push the result to the newArray
}
return newArray;
}
const arr = [1,2,3,4,5];
console.log(arr.myMap((element) => ++element));
// please include the steps! I just want to learn how to make this from scratch