Skip to content

Pass Test #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const changeToArray = (collection) => Array.isArray(collection) ? collection : Object.values(collection)
const multiplyByThree = (num) => num * 3
const alertMe = (item) => alert(`${item}`)
const callback = (acc, i, array) => (acc + (i * 3))
const callback2 = (acc, val, collection) => (acc + val )
function findCBGenerator(target) {
return (function(currEl) { return target === currEl })
}
Comment on lines +1 to +8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up, clean up, everybody do their share!


const myEach = (collection, callbackFunc) => {
changeToArray(collection).forEach(callbackFunc)
return collection
}

const myMap = (collection, callbackFunc) => changeToArray(collection).map(callbackFunc)

const myReduce = (collection, callbackFunc, acc) => {
const array = changeToArray(collection)
let startIndex = 0
if(!acc){
acc = array[0]
startIndex = 1
}
let total = acc
for(let i = startIndex; i < array.length; i++){
acc = callbackFunc(acc, array[i],array)
}
return acc
}


const myFind = (collection, callBackFunc) => {
const array = changeToArray(collection)
for(let i = 0; i < array.length; i++){
if(callBackFunc(collection[i])){
return collection[i]
}
}
return
}

function excluder(currEl) {
return (currEl > 10)
}

const myFilter = (collection, callBackFunc) => {
const array = changeToArray(collection)
let returnArray = []
for(let i = 0; i < array.length; i++){
if(callBackFunc(array[i])){
returnArray.push(array[i])
}
}
return returnArray
}

const mySize = (collection) => {
const array = changeToArray(collection)
return array.length
}

const myFirst = (collection, elemsToReturn) => {
const array = changeToArray(collection)
if(!elemsToReturn){
return array[0]
}else{
return array.splice(0,elemsToReturn)
}
}

const myLast = (collection, elemsToReturn) => {
const array = changeToArray(collection)
if(!elemsToReturn){
return array[array.length - 1]
}else{
return array.splice(-elemsToReturn)
}
}

const myKeys = (collection) => {
const returnKeys = []
for(const key in collection)[
returnKeys.push(key)
]
return returnKeys
}

const myValues = (collection) => {
const returnValues = []
for(const key in collection){
returnValues.push(collection[key])
}
return returnValues
}