Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <script>
- //--------------------------------------
- function message(input_message){
- document.write(input_message);
- };
- function three_five(maxlen){
- var nums = [];
- var num = 1;
- while (nums.length < maxlen){
- if (num%3==0&&num%5==0){
- nums.push(num);
- }
- num = num + 1
- }
- return nums;
- };
- //--------------------------------------
- function is_anagram(word1,word2){
- if (word1.length != word2.length){
- return false;
- }
- for (var i=0,len=word1.length;i<len;i++){
- if (word1.split(word1[i]).length-1 != word2.split(word1[i]).length-1){
- return false;
- }
- }
- return true;
- };
- //--------------------------------------
- function replace_letter(word,letter){
- while (word.indexOf(letter) != -1){
- word = word.replace(letter,"");
- }
- return word;
- };
- //--------------------------------------
- function sum_array(array){
- var total = 0;
- for (var i=0,len=array.length;i<len;i++){
- total += array[i];
- }
- return total;
- }
- //--------------------------------------
- function bubble_sort(array){
- var sorted = false;
- while (sorted == false){
- sorted = true;
- for (var i=0,len=array.length;i<len;i++){
- if (array[i] > array[i+1]){
- sorted = false;
- var x = array[i+1];
- array[i+1] = array[i];
- array[i] = x;
- }
- }
- }
- return array;
- }
- document.write("--Output 'Hello World' to the console.<br>")
- message("Hello World<p>");
- document.write("--Return an array of the first 100 numbers that are divisible by 3 and 5.<br>")
- document.write(three_five(100));
- document.write("<p>")
- document.write("--Create a program that verifies if a word is an anagram of another word.<br>")
- document.write("word1 = 'racecar'<br>word2='carrace'<br>result = ");
- document.write(is_anagram("racecar","carrace"));
- document.write("<p>");
- document.write("--Create a program that removes a specificed letter from a word.<br>")
- document.write("word = 'aaaaaaaeeeeaaa'<br>letter = 'a'<br>result = ");
- document.write(replace_letter("aaaaaaaeeeeaaa","a"));
- document.write("<p>");
- document.write("--Sum all the elements of an array.<br>")
- document.write("array = [1,2,3,4,5,6,7,8,9,10]<br>result = ")
- document.write(sum_array([1,2,3,4,5,6,7,8,9,10]))
- document.write("<p>");
- document.write("--Implement a bubble-sort.<br>");
- document.write("array = [3,1,2,7,5,4,9,10,8]<br>")
- document.write(bubble_sort([3,1,2,7,5,4,9,10,8]));
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement