To complete this lab (as for most labs), do the following:
- Fork this repo.
- Clone your forked repo.
- Create a file called
arrays_lab.js
inside your cloned repo. - Copy the description of the exercise as a comment.
- Underneath the commented description write your code.
- Ensure your solutions work properly!
- Open PR against this repo.
-
Log the last element of an array.
-
Change the first element of an array to the string "something else".
-
Add "mango" to the end of a fruits array ["strawberry", "banana"].
-
Add "blueberry" to the front of the same fruits array.
-
Remove the last element of the fruits array.
-
console.log the length of the fruits array.
-
Remove the first element of the fruits array.
-
Join all the elements in the fruits array with a '$'.
-
Given two arrays, write code that logs the larger array. If the arrays are the same length, log "They are the same size"
let firstArr = [1,2,3]
let secondArr = [1,5,2,4]
// log [1,5,2,4]
- Given an array, log its middle element. If the middle of the array is between two elements, log both of them.
let hasExactMiddleArr = [1,5,3]
// log 5
let hasNoExactMiddleArr = [1,4,6,9]
// log 4,6
- Write code that logs every value in an array using a for loop
let logMeOutFor = ["I", "am", "a", "happy", "array"]
/* I
am
a
happy
array
*/
- Write code that logs every value in an array using a while loop
let logMeOutWhile = ["I", "am", "a", "happy", "array"]
/* I
am
a
happy
array
*/
- Write code that logs every value in an array using a for/of loop
let logMeOutForOf = ["I", "am", "a", "happy", "array"]
/* I
am
a
happy
array
*/
- Given an array of numbers, write code that logs the sum of all the numbers
let firstArrToSum = [1, 2, 3, 4, 5, 6]
// 21
let secondArrToSum = [1, 2, 3, 4, 5, -6]
// 9
- Given an array of numbers, write code that logs all the odd numbers
let evenAndOddArr = [1,5,2,4,11,12,99,100]
// 1, 5, 11, 99
- Given an array of numbers, write code that logs the sum of all the even numbers
let evenAndOddArrToSum = [1,5,2,3,11,4,6]
// 12
- Write code such that noDupeList has all the same numbers as dupeFriendlyList, but has no more than one of each number.
let dupeFriendlyList = [4,2,6,2,2,6,4,9,2,1]
let noDupeList = []
// noDupleList = [4, 2, 6, 9, 1]
- Make an array that contains all elements that appear exactly once in someRepeatsAgain
let someRepeatsAgain = [25,11,30,31,50,28,4,37,13,20,24,38,28,14,44,33,7,43,39,35,36,42,1,40,7,14,23,46,21,39,11,42,12,38,41,48,20,23,29,24,50,41,38,23,11,30,50,13,13,16,10,8,3,43,10,20,28,39,24,36,21,13,40,25,37,39,31,4,46,20,38,2,7,11,11,41,45,9,49,31,38,23,41,16,49,29,14,6,6,11,5,39,13,17,43,1,1,15,25]
// [ 44,33,35,42,12,48,30,50,8,3,10,28,24,36,21,1000,40,37,4,46,20,2,7,45,9,31,38,23,41,16,49,29,14,6,11,5,39,13,17,43,1,15,25 ]
- Given an array of strings, find the the string with the most "a"s in it.
let mostAStrings = ["apes", "abba", "apple"]
//"abba"
- Find the second smallest number in an Array of Ints
let secondSmallestArr = [11, 52, 10, 7, 50, 46, 79, 78, 13, 26, 83, 92, 89, 81, 1, 41, 4, 23, 57, 41, 80, 83, 41, 69]
// 4