← 返回 ibm 的题目列表JSON Prediction Diff
类型:qbank
Parse two JSON-formatted strings and return keys whose values differ between the two prediction objects.
Requirements
Function: getPredictionDiff(predictions1, predictions2).
Input: two JSON-formatted strings representing flat key/value maps.
Output: a string list containing keys that appear in both maps but have different values.
Keys absent from the second map are not counted as value differences in the provided implementation pattern.
Examples
predictions1 = '{"hacker":"rank","input":"output","same":"yes"}'
predictions2 = '{"hacker":"rank","input":"wrong","same":"yes"}'
Output: ["input"]
Notes
Use a standard JSON parser rather than manually splitting on punctuation.
Iterate over keys from the first object, look up the corresponding second value, and append the key when both values exist and differ.
The prompt is intentionally short; the main signal is clean parsing and simple map comparison.
Preparation
Use the language's JSON parser and decide the value comparison semantics before coding: strings only, primitive values, or arbitrary JSON values.
Add tests for missing keys, same keys in different order, escaped quotes, numeric-looking strings, and invalid JSON if the platform expects exception handling.