Topic
Iterators — Review in the Learn JavaScript Syntax: Iterators module.
I’m working on Safari 14.0, Catalina 10.15.7.
Summary of the report:
I was trying some things out in the Codeacademy editor, working through the ‘Challenge Yourself’ section at the end. I tried using the .flat()
method on a nested array, but it wouldn’t work. It did work in my own editor.
Steps to Reproduce:
My code was as follows:
const arr = [2, 4, 6, 8, 10];
const nestedArr = ["a", "b", "c", ["x", "y", "z"]];
// Callback function
const timesTwo = (num) => num * 2;
// forEach
arr.forEach((number) => console.log(timesTwo(number)));
// map
console.log(arr.map((number) => timesTwo(number)));
// Chaining iterators (map, then filter)
console.log(arr.map((number) => timesTwo(number)).filter((num) => num > 10));
const singleLayer = nestedArr
.reduce((acc, curr) => acc + curr)
.split("")
.filter((element) => element !== ",");
console.log(singleLayer);
console.log(nestedArr.flat());
The output is:
4
8
12
16
20
[ 4, 8, 12, 16, 20 ]
[ 12, 16, 20 ]
[ 'a', 'b', 'c', 'x', 'y', 'z' ]
/home/ccuser/workspace/javascript-iterators-iterators-review/main.js:21
console.log(nestedArr.flat());
^
TypeError: nestedArr.flat is not a function
at Object.<anonymous> (/home/ccuser/workspace/javascript-iterators-iterators-review/main.js:21:23)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3
Fix or Workaround: Unknown
Please attach screenshots