Write a function to extract all time zones from the iNaturalist observation results. * The time zones
Question:
Write a function to extract all time zones from the iNaturalist observation results.
* The time zones are available in each result's `created_time_zone` and
* `observed_time_zone` properties.
*
* Your function should loop through all of the results in `data` and get the
* time zone values, placing them in an Array.
*
* You should not put any duplicate values in your new Array.
*
* When you have processed all results, and collected all unique time zone values,
* return the Array of time zones.
*/
function extractTimeZones(data) {
write the code here
}
/**
* Problem 08: Part 2 - extractTimeZones2()
*
* Rewrite your `extractTimeZones` function from above, but do not use an Array
* to hold the time zones. Instead, use a Set, see:
*
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
*
* Your function should store all unique time zones in a Set, and when you are done
* processing all results, convert your Set to an Array and return it. See:
*
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
*/
function extractTimeZones2(data) {
write the code here
}
----------------------------------------------
data.test.js
const { extractTimeZones, extractTimeZones2 } = require('./observations');
const data = require('./data');
const result0 = data.results[0];
const result1 = data.results[1];
describe('extractTimeZones() and extractTimeZones2', () => {
[extractTimeZones, extractTimeZones2].forEach((fn) => {
test('should return a single result', () => {
expect(fn({ results: [result0] })).toEqual(['Pacific/Honolulu']);
});
test('extractTimeZones should not return duplicates', () => {
expect(fn({ results: [result0, result0] })).toEqual(['Pacific/Honolulu']);
});
test('extractTimeZones should not deal properly with multiple values without duplicating', () => {
expect(fn({ results: [result0, result0, result1, result1] })).toEqual([
'Pacific/Honolulu',
'America/New_York'
]);
});
test('extractTimeZones should work on real data', () => {
expect(fn(data)).toEqual(['Pacific/Honolulu', 'America/New_York']);
});
});
});
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill