Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add(a, b) {
- return a + b;
- }
- const newAdd = (a, b) => a + b;
- const operate = (op1, op2, operation) => operation(op1, op2)
- // console.log(operate(5, 10, (a, b) => a + b))
- const arrayOperation = (arr, opOnEle) => {
- for (i = 0; i < arr.length; i++) {
- opOnEle(arr[i])
- }
- }
- const arr1 = [1, 10, 20, 30, 40];
- // arrayOperation([10, 20, 30], (ele) => console.log(ele))
- // arr1.forEach((ele) => console.log(ele))
- // ----------------------------------
- // [1,2,3,4] -> [1,4,9,16]
- const mapOperation = (arr, operation) => {
- const result = []
- for (i = 0; i < arr.length; i++) {
- const res = operation(arr[i])
- result.push(res)
- }
- return result
- }
- const filterOperation = (arr, condition) => {
- const result = [];
- for (i = 0; i < arr.length; i++) {
- const r = condition(arr[i])
- if (r) {
- result.push(arr[i])
- }
- }
- return result;
- }
- // console.log(filterOperation(arr1, (ele) => ele % 2 == 0))
- // console.log(mapOperation(arr1, (ele) => ele * ele))
- // console.log(mapOperation(arr1, (ele) => ele * ele * ele))
- // console.log(arr1.map((ele) => ele * ele))
- // console.log(arr1.filter((e) => e % 2 == 0))
- const student = {
- name: "mahadev",
- college: "jspm",
- roll: 10
- }
- // console.log(student["name"])
- // find all students of JSPM college and having marks
- // greater than 20% and return rollNumbers of them
- const students = [
- {
- name: "mahadev",
- college: "jspm",
- roll: 10,
- marks: 30
- },
- {
- name: "mahadev1",
- college: "BSIOTR",
- roll: 11,
- marks: 20
- },
- {
- name: "mahadev2",
- college: "jspm",
- roll: 12,
- marks: 10
- }
- ]
- students.filter(s => s.college == "jspm")
- const rolls = students.filter((student) => student.college == "jspm")
- .filter((student) => student.marks > 20)
- .map(student => student.roll)
- // console.log(rolls)
- const task = (success, failure) => {
- console.log("data is performing certaion operation")
- console.log("searching for mobile num,ber")
- setTimeout(() => {
- console.log("task got failed ")
- const resultOfTask = 9096969220;
- failure(resultOfTask)
- }, 1000)
- }
- const dattasPromise = new Promise(task)
- const suuccessCallback = (result) => {
- console.log("I got mobile number from datta", result)
- console.log("calloing that numnber")
- }
- const failureCallback = (err) => {
- console.log("Datta has failed to perform operation and here is error: ", err)
- console.log("I may try to do some other way")
- }
- dattasPromise.then(suuccessCallback).catch(failureCallback)
- console.log("assigned operation to datta and continueing my other work")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement