Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. let testArr = ["hej", "Skoæske", "wjiiojo", "klsjdlkasjlkjdlasjd", "2s"];
  2.  
  3. function mindreEnd(a, b) {
  4. if(typeof a == 'number' && typeof b == 'number') {
  5. if(a < b){
  6. return true;
  7. } else {
  8. return false;
  9. }
  10. } else if (typeof a == 'string' && typeof b == 'string') {
  11. if(a.length < b.length){
  12. return true;
  13. } else {
  14. return false;
  15. }
  16. } else {
  17. throw Error ("Input must be the same");
  18. }
  19. };
  20.  
  21. function test(array) {
  22. let mindst = array[0];
  23. for(let i of array){
  24. if(mindreEnd(i, mindst) == true){
  25. mindst = i;
  26. }
  27. }
  28. console.log("Mindste element er: " + mindst);
  29. };
  30.  
  31. test(testArr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement