AT END MISSING "}"
// FUNCTION DEFINITION(S)
function map(array, callbackFunction) {
var newArray = [];
for (var i = 0; i < array.length; i++) {
var element = array[i];
newArray = newArray + callbackFunction(element);
}
return newArray;
}
function cubeAll(numbers) {
return map(numbers, function(n) {
return n * n;
});
}
// ASSERTION FUNCTION(S) TO BE USED
function assertArraysEqual(actual, expected, testName){
var hasSameVal = true;
for(var i = 0; i < actual.length; i++){
if(actual[i]!== expected[i]){
hasSameVal === false;
break;
}
}
var SameLength = actual.length === expected.length;
if(hasSameVal && SameLength){
console.log('Passed');
} else{
console.log('FAILED ['+testName+ '] Expected ' +expected+' , but got '+actual);
}
}
// TESTS CASES
function addOne(val){
return val + 1;
}
var inputForMap = [1, 2, 3];
var actualMap = map[inputForMap, addOne];
var expectedMap =[2, 3, 4]
assertArraysEqual(actualMap, expectedMap, "should correctly map elements of an array");
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}