Created
June 26, 2019 12:22
-
-
Save wavesailor/14c93f1fa032becf9055eb5b24cc0ccf to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/nevonet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// 1. create a constant named friends, | |
// which is an array that contains 2 | |
// names of your choosing. | |
'use strict'; | |
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } | |
var friends = ['Joe', 'Jane']; | |
// 2. Create a new constant named updatedFriends, | |
// which includes the friends array values plus | |
// one additional name | |
var updatedFriends = [].concat(friends, ['Billy']); | |
// 3. Create a new constant named friendNameLengths, | |
// which is based on the array updatedFriends, | |
// but instead of having the friends names, | |
// have the array store the length of each persons name. | |
var friendNameLengths = updatedFriends.map(getFriendNameLen); | |
function getFriendNameLen(name) { | |
return name.length; | |
}; | |
// 4. Create a new constant named shorterNamedFriends, | |
// which will be a list of the friends except the friend with the longest name. | |
var maxFriendLength = Math.max.apply(Math, _toConsumableArray(friendNameLengths)); | |
var shorterNamedFriend = updatedFriends.filter(function (name) { | |
return name.length < maxFriendLength; | |
}); | |
// 5. Print each variable to the console. | |
console.log(friends, updatedFriends, friendNameLengths, shorterNamedFriends); | |
// Solution can be seen at: | |
// https://jsbin.com/nevonet/1/edit?js,console | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// 1. create a constant named friends, | |
// which is an array that contains 2 | |
// names of your choosing. | |
const friends = ['Joe', 'Jane']; | |
// 2. Create a new constant named updatedFriends, | |
// which includes the friends array values plus | |
// one additional name | |
const updatedFriends = [...friends, 'Billy'] | |
// 3. Create a new constant named friendNameLengths, | |
// which is based on the array updatedFriends, | |
// but instead of having the friends names, | |
// have the array store the length of each persons name. | |
const friendNameLengths = updatedFriends.map(getFriendNameLen); | |
function getFriendNameLen (name) { | |
return name.length; | |
}; | |
// 4. Create a new constant named shorterNamedFriends, | |
// which will be a list of the friends except the friend with the longest name. | |
const maxFriendLength = Math.max(...friendNameLengths); | |
const shorterNamedFriend = updatedFriends.filter( | |
function(name){ | |
return name.length < maxFriendLength ; | |
}); | |
// 5. Print each variable to the console. | |
console.log(friends, updatedFriends,friendNameLengths,shorterNamedFriends); | |
// Solution can be seen at: | |
// https://jsbin.com/nevonet/1/edit?js,console</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. create a constant named friends, | |
// which is an array that contains 2 | |
// names of your choosing. | |
'use strict'; | |
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } | |
var friends = ['Joe', 'Jane']; | |
// 2. Create a new constant named updatedFriends, | |
// which includes the friends array values plus | |
// one additional name | |
var updatedFriends = [].concat(friends, ['Billy']); | |
// 3. Create a new constant named friendNameLengths, | |
// which is based on the array updatedFriends, | |
// but instead of having the friends names, | |
// have the array store the length of each persons name. | |
var friendNameLengths = updatedFriends.map(getFriendNameLen); | |
function getFriendNameLen(name) { | |
return name.length; | |
}; | |
// 4. Create a new constant named shorterNamedFriends, | |
// which will be a list of the friends except the friend with the longest name. | |
var maxFriendLength = Math.max.apply(Math, _toConsumableArray(friendNameLengths)); | |
var shorterNamedFriend = updatedFriends.filter(function (name) { | |
return name.length < maxFriendLength; | |
}); | |
// 5. Print each variable to the console. | |
console.log(friends, updatedFriends, friendNameLengths, shorterNamedFriends); | |
// Solution can be seen at: | |
// https://jsbin.com/nevonet/1/edit?js,console |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment