Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. let none_alone = (coll, fit) => {
  2. let[first,second,third, ...tail] = [...coll]
  3. let skip_one = () => ([first, second, third, ...tail] =
  4. [second, third, ...tail])
  5. let skip_third = () => ([first, second, third, ...tail] =
  6. [...tail])
  7. while(first !== undefined) {
  8. if(!fit(first)) skip_one()
  9. else if(!fit(second)) return false
  10. else if(!fit(third)) skip_third()
  11. else skip_one()
  12. }
  13. return true
  14. }
  15.  
  16. let gHappy = (str) => none_alone(str, (c) => (c == 'g'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement