Skip to content

Instantly share code, notes, and snippets.

View mdn102's full-sized avatar
🏠
Working from home

Minh Nguyen mdn102

🏠
Working from home
View GitHub Profile
@mdn102
mdn102 / AllUnderscoreMethods.js
Created April 22, 2020 21:58 — forked from alexhawkins/AllUnderscoreMethods.js
Basic Implementation of 'most' Underscore Methods from Scratch
var _ = {};
/*********IDENTITY**********/
_.identity = function(val) {
return val;
};
/*********FIRST**********/
_.first = function(array, n) {
// #2
/*
Write an "assertArraysEqual" function from scratch.
Assume that the arrays in question contain only scalar values (i.e., simple values like strings or numbers).
Do not use JSON.stringify(), Array.join(), or any other "convert the array to a string so I can compare two strings" type of technique to implement this.
Examples
SUCCESS CASE
var expected = ['b', 'r', 'o', 'k', 'e', 'n'];
var actual = 'broken'.split('');
assertArraysEqual(actual, expected, 'splits string into array of characters');