Guest User

Untitled

a guest
Dec 14th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. var foo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
  2. find = [1, 10, 20],
  3. b = 21,
  4. i = find.length,
  5. indexOfUsingWhile = function (needle, haystack) {
  6. var j = haystack.length;
  7. while (j) {
  8. j -= 1;
  9. if (haystack[j] === needle) {
  10. return j;
  11. }
  12. }
  13. return -1;
  14. };
  15.  
  16. while (i--) {
  17. console.log(indexOfUsingWhile(find[i], foo));
  18. }
  19. i = find.length;
  20. while (i--) {
  21. console.log(foo.indexOf(find[i]));
  22. }
  23. i = find.length;
  24. while (i--) {
  25. console.log(indexOfUsingWhile(b, foo));
  26. }
  27. i = find.length;
  28. while (i--) {
  29. console.log(foo.indexOf(b));
  30. }
Add Comment
Please, Sign In to add comment