SHARE

TWEET

# Untitled

a guest
Oct 19th, 2019
67
Never

**Not a member of Pastebin yet?**

**, it unlocks many cool features!**

__Sign Up__- /**
- * Seven students A, B, C, D, E, F and G are sitting in a row.
- * G is between A and E.
- * F and A have one student between them.
- * E and C have two students between them.
- * D is immediate right of F.
- * C and B have three students between them.
- */
- const swap = (array, a, b) => {
- [array[a], array[b]] = [array[b], array[a]]
- }
- let row = ["A", "B", "C", "D", "E", "F", "G"]
- // G is between A and E
- swap(row, row.indexOf("A"), row.indexOf("G") + 1)
- swap(row, row.indexOf("E"), row.indexOf("G") - 1)
- // F and A have one student between them
- swap(row, row.indexOf("F"), row.indexOf("A") + 2)
- // E and C have two students between them
- swap(row, row.indexOf("C"), row.indexOf("A") + 1)
- // D is to the immediate right of F
- swap(row, row.indexOf("D"), row.indexOf("F") + 1)
- row = row.filter(Boolean)
- console.log("Who is sitting in the middle? - ", row[Math.floor(row.length / 2)])
- console.log("Sequence of the students - ", row.join(" "))

RAW Paste Data

We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.