-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import { GraphData } from "../../Types"; | ||
import { GraphData } from '../../Types' | ||
|
||
export function differentiateArrayObjects(arr: GraphData[]): GraphData[] { | ||
return arr.map((currentObj, index, array) => { | ||
// Handling for the last element since it has no successor | ||
if (index === array.length - 1) { | ||
const lastObj: GraphData = { size: currentObj.size }; // Preserving the size property | ||
// Set all other properties to NaN or 0 to indicate no difference can be calculated | ||
Object.keys(currentObj).forEach((key) => { | ||
if (key !== 'size') { | ||
lastObj[key] = NaN; // or set to 0 as per requirement | ||
} | ||
}); | ||
return lastObj; | ||
return arr.map((currentObj, index, array) => { | ||
// Handling for the last element since it has no successor | ||
if (index === array.length - 1) { | ||
const lastObj: GraphData = { size: currentObj.size } // Preserving the size property | ||
// Set all other properties to NaN or 0 to indicate no difference can be calculated | ||
Object.keys(currentObj).forEach(key => { | ||
if (key !== 'size') { | ||
lastObj[key] = NaN // or set to 0 as per requirement | ||
} | ||
}) | ||
return lastObj | ||
} | ||
|
||
const nextObj = array[index + 1]; | ||
const differentiatedObj: GraphData = { size: currentObj.size }; // Preserve the size property | ||
const nextObj = array[index + 1] | ||
const differentiatedObj: GraphData = { size: currentObj.size } // Preserve the size property | ||
|
||
// Iterate over the properties of the current object | ||
Object.keys(currentObj).forEach((key) => { | ||
if (key !== 'size' && typeof currentObj[key] === 'number') { | ||
// Calculate the difference with the next object's corresponding property | ||
const difference = (nextObj[key] || 0) - currentObj[key]; | ||
differentiatedObj[key] = parseFloat(difference.toFixed(3)); | ||
} | ||
}); | ||
// Iterate over the properties of the current object | ||
Object.keys(currentObj).forEach(key => { | ||
if (key !== 'size' && typeof currentObj[key] === 'number') { | ||
// Calculate the difference with the next object's corresponding property | ||
const difference = (nextObj[key] || 0) - currentObj[key] | ||
differentiatedObj[key] = parseFloat(difference.toFixed(3)) | ||
} | ||
}) | ||
|
||
return differentiatedObj; | ||
}); | ||
} | ||
return differentiatedObj | ||
}) | ||
} |