Guest User

Untitled

a guest
Feb 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. let array1 = [1,2,'a',3,'b',4,5]
  2. let array2 = [1,2,'a',3,'b',4,5,6,'k']
  3.  
  4. const checkIfArrayHasNValuesOfSameDataTypeCohesively = datatype => n => array => {
  5. let _n = 0;
  6. for (let i = 0; i < array.length; i++) {
  7. if (typeof array[i] == datatype) {
  8. if (++_n >= n) return true;
  9. }
  10. else {
  11. _n = 0;
  12. }
  13. }
  14. return false;
  15. }
  16.  
  17. checkIfArrayHasNValuesOfSameDataTypeCohesively('number')(3)(array1); // false
  18. checkIfArrayHasNValuesOfSameDataTypeCohesively('number')(3)(array2); // true
Add Comment
Please, Sign In to add comment