---
# System prepended metadata

title: Three exercises for Asa

---

# Three exercises for Asa

- Write a JavaScript program to get every nth element in a given array.
- `console.log(everyNth([1, 2, 3, 4, 5, 6], 1));
console.log(everyNth([1, 2, 3, 4, 5, 6], 2));
console.log(everyNth([1, 2, 3, 4, 5, 6], 3));
console.log(everyNth([1, 2, 3, 4, 5, 6], 4));`


- Write a JavaScript function that returns true if the provided predicate function returns true for all elements in a collection, false otherwise.
- `console.log(predicateApplied([4, 2, 3], x => x > 1));
console.log(predicateApplied([4, 2, 3], x => x < 1));`

- Write a JavaScript program to extract out the values at the specified indexes from a specified array. 
- `const arra1 = ['a', 'b', 'c', 'd', 'e', 'f'];
console.log(pullAtIndex(arra1, [1, 3]));
const arra2 =  [1, 2, 3, 4, 5, 6, 7];
console.log(pullAtIndex(arra2, [4]));`


- The solutions I created are below:


- Write a JavaScript program to get every nth element in a given array.
- `const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);`
- Write a JavaScript function that returns true if the provided predicate function returns true for all elements in a collection, false otherwise.
- `const predicateAppliedTwo = (array, predicate) => array.filter(element => predicate(element)).length === array.length;`
-  Write a JavaScript program to extract out the values at the specified indexes from a specified array. 
-  `const pullAtIndex = (array, indexes) => indexes.map(index => array[index])`

