My soln:
// the global Array
var s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback){
var newArray = [];
// Add your code below this line
this.forEach(
item=>| const I = x => x; | |
| const K = x => y => x; | |
| const A = f => x => f(x); | |
| const T = x => f => f(x); | |
| const W = f => x => f(x)(x); | |
| const C = f => y => x => f(x)(y); | |
| const B = f => g => x => f(g(x)); | |
| const S = f => g => x => f(x)(g(x)); | |
| const P = f => g => x => y => f(g(x))(g(y)); | |
| const Y = f => (g => g(g))(g => f(x => g(g)(x))); |
My soln:
// the global Array
var s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback){
var newArray = [];
// Add your code below this line
this.forEach(
item=>| 'use strict'; | |
| /*****************NATIVE forEACH*********************/ | |
| Array.prototype.myEach = function(callback) { | |
| for (var i = 0; i < this.length; i++) | |
| callback(this[i], i, this); | |
| }; | |
| //tests |
The variable watchList holds an array of objects with information on several movies.
Use a combination of filter and map on watchList to assign a new array of objects
with only title and rating keys. The new array should only include objects where
imdbRating is greater than or equal to 8.0.
Note that the rating values are saved as strings in the object
and you may need to convert them into numbers to perform mathematical operations on them.
My slon:
// the global variableWrite your own Array.prototype.myMap(), which should behave exactly
like Array.prototype.map(). You may use a for loop or the forEach method.
My first attempt:
// the global Array
var s = [23, 65, 98, 5];
Array.prototype.myMap = function(callback){
var newArray = [];| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Array.splice Implementation</title> | |
| <link rel="stylesheet" type="text/css" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css" /> | |
| <script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script> | |
| <script type="text/javascript"> | |
| if (!Array.prototype.splice2) { | |
| Array.prototype.splice2 = function(index, howmany) { | |
| if (index < 0) { |
| /* | |
| Basic Algorithm Scripting: Chunky Monkey | |
| Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array. | |
| tests: | |
| - text: <code>chunkArrayInGroups(["a", "b", "c", "d"], 2)</code> should return <code>[["a", "b"], ["c", "d"]]</code>. | |
| testString: assert.deepEqual(chunkArrayInGroups(["a", "b", "c", "d"], 2), [["a", "b"], ["c", "d"]]); | |
| - text: <code>chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3)</code> should return <code>[[0, 1, 2], [3, 4, 5]]</code>. | |
| testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3), [[0, 1, 2], [3, 4, 5]]); | |
| - text: <code>chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2)</code> should return <code>[[0, 1], [2, 3], [4, 5]]</code>. | |
| testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2), [[0, 1], [2, 3], [4, 5]]); |
| /* | |
| Basic Algorithm Scripting: Mutations | |
| Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array. | |
| For example, ["hello", "Hello"], should return true because all of the letters in the second string are present in the first, ignoring case. | |
| The arguments ["hello", "hey"] should return false because the string "hello" does not contain a "y". | |
| Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien". |
| /* | |
| Basic Algorithm Scripting: Where do I Belong | |
| Return the lowest index at which a value (second argument) should be inserted into an array | |
| (first argument) once it has been sorted. The returned value should be a number. | |
| For example, getIndexToIns([1,2,3,4], 1.5) should return 1 because it is greater than 1 (index 0), but less than 2 (index 1). | |
| Likewise, getIndexToIns([20,3,5], 19) should return 2 because once the array has been sorted | |
| it will look like [3,5,20] and 19 is less than 20 (index 2) and greater than 5 (index 1). | |
| */ | |
| //My soln: | |
| function getIndexToIns(arr, num) { |