// Remove all the values
function destroyer(arr) {
// create filter list filterMe and fill it with all elements in arr except arr[0]
var filterMe = [];
for (var z = 1; z<arr.length; z++) {
filterMe.push(arr[z]);
}
// create a list of numbers which represent the indexes of arr elements to filter
var filterIndex = [];
// for loop through arr[0]
for (var y = 0; y<arr[0].length; y++) {
// for loop through filterMe
for (var x = 0; x<filterMe.length; x++) {
// if arr[0][y] === filterMe[x]
if (arr[0][y]===filterMe[x]) {
// push the index 'x' to filterIndex
filterIndex.push(x); // will contain list of all indexes to splice.
}
}
}
// new array to hold elements not cut from old arr[0]
var newArray = [];
// keep track of how many indexes have been cut with 'count'
var count = 0;
// iterate through filterIndex
for (var q=0; q<filterIndex.length; q++) {
// for loop through arr[0] again to find values not to cut
for (var r=0; r<arr[0].length; r++) {
// if filterIndex[q]===r then skip that number
if (filterIndex[q]===r) { // keep track of which filterIndex we're at with 'q'
// skip and add 1 to 'count'
count++;
} else {
newArray.push(arr[0][r-count]); // will only pick up the arr[0] elements not skipped
}
}
}
return newArray;
}
//test:
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
const textAreaStyles = {
width: 235,
margin: 5
};
class MyToDoList extends React.Component {
constructor(props) {
super(props);
// change code below this line
this.state = {
userInput: '',
toDoList: []
};
// change code above this line
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
}
handleSubmit() {
const itemsArray = this.state.userInput.split(',');
this.setState({
toDoList: itemsArray
});
}
handleChange(e) {
this.setState({
userInput: e.target.value
});
}
render() {
const items = this.state.toDoList.map((x) => {
return <li> {x} </li>;
});
return (
<div>
<textarea
onChange={this.handleChange}
value={this.state.userInput}
style={textAreaStyles}
placeholder="Separate Items With Commas" /><br />
<button onClick={this.handleSubmit}>Create List</button>
<h1>My "To Do" List:</h1>
<ul>
{items}
</ul>
</div>
);
}
};
The test that I am failing says:
"When the Create List button is clicked, the MyToDoList component should dynamically return an unordered list that contains a list item element for every item of a comma-separated list entered into the textarea element. };"
for
loop
var factorialize(5)
is invalid code
var
keyword to define variables with the name that comes right after them
num
"?