Question: I create some code to find AccessibilityId after swipe action, but it did "not" go into my while condition. ***How to make condition to find AccessibilityId?***

This is scenario I want.

```
1.Launch app, there is no test1_action buttons (AccessibilityId = test1_action)
2.To Click test1_action, will repeat swipe "i" times till find AccessibilityId.
3.After "i" times swiping, if there will be test1_action button then it will click it

```

iOS/iPhone/Appium

```
WebDriverWait wait = new WebDriverWait(driver, 20);
int i = 0;
while 
(!driver.findElement(MobileBy.AccessibilityId("test1_action")).isDisplayed()) {
    swipe(331, 544, 50, 544, 2);
    i++;
        }
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("test1_action"))).click();

```

When i run this, I faced below error

> 
> Caused by: org.openqa.selenium.NoSuchElementException: An element
>  could not be located on the page using the given search parameters.
> 
> 
>

Answer: 
```js
var array1 = [
  {
    course: "ABC",
    skills:["skill1", "skill2"]
  },
  {
    course: "DEF",
    skills: ["skill1"]
  },
  {
    course: "GHI",
    skills: ["skill1", "skill2", "skill3"]
  }
];

const flatten = array =>
  array.reduce((results, item) => [...results, ...item.skills.map(skill => ({ course: item.course, skill: skill }))], []);

console.log(flatten(array1));
```
Kind of the opposite of what most people want! Here you go - a version using `reduce` and spreading:

```js
var array1 = [
  {
    "course": "ABC",
    "skills":["skill1", "skill2"],
  },
  {
    "course": "DEF",
    "skills":["skill1"],
  },
  {
    "course": "GHI",
    "skills":["skill1", "skill2", "skill3"],
  }
];

const res = array1.reduce((a, { skills, ...c }) => {
  skills.forEach(skill => a.push({ ...c, skills: skill }));
  return a;
}, []);

console.log(res);
```